@buoy-gg/events 7.0.29 → 7.0.31

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 (89) hide show
  1. package/lib/commonjs/components/EventsCopySettingsView.js +15 -1
  2. package/lib/commonjs/components/EventsCopySettingsView.js.map +1 -1
  3. package/lib/commonjs/components/EventsModal.js +28 -7
  4. package/lib/commonjs/components/EventsModal.js.map +1 -1
  5. package/lib/commonjs/components/UnifiedEventDetail.js +23 -3
  6. package/lib/commonjs/components/UnifiedEventDetail.js.map +1 -1
  7. package/lib/commonjs/components/UnifiedEventFilters.js +15 -0
  8. package/lib/commonjs/components/UnifiedEventFilters.js.map +1 -1
  9. package/lib/commonjs/components/UnifiedEventItem.js +23 -6
  10. package/lib/commonjs/components/UnifiedEventItem.js.map +1 -1
  11. package/lib/commonjs/components/UnifiedEventList.js +13 -1
  12. package/lib/commonjs/components/UnifiedEventList.js.map +1 -1
  13. package/lib/commonjs/hooks/useUnifiedEvents.js +118 -117
  14. package/lib/commonjs/hooks/useUnifiedEvents.js.map +1 -1
  15. package/lib/commonjs/index.js +25 -0
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/stores/unifiedEventStore.js +57 -3
  18. package/lib/commonjs/stores/unifiedEventStore.js.map +1 -1
  19. package/lib/commonjs/utils/autoDiscoverEventSources.js +54 -0
  20. package/lib/commonjs/utils/autoDiscoverEventSources.js.map +1 -1
  21. package/lib/commonjs/utils/badgeSelectionStorage.js +36 -0
  22. package/lib/commonjs/utils/badgeSelectionStorage.js.map +1 -1
  23. package/lib/commonjs/utils/testIDs.js +91 -0
  24. package/lib/commonjs/utils/testIDs.js.map +1 -0
  25. package/lib/module/components/EventsCopySettingsView.js +15 -1
  26. package/lib/module/components/EventsCopySettingsView.js.map +1 -1
  27. package/lib/module/components/EventsModal.js +30 -8
  28. package/lib/module/components/EventsModal.js.map +1 -1
  29. package/lib/module/components/UnifiedEventDetail.js +23 -3
  30. package/lib/module/components/UnifiedEventDetail.js.map +1 -1
  31. package/lib/module/components/UnifiedEventFilters.js +15 -0
  32. package/lib/module/components/UnifiedEventFilters.js.map +1 -1
  33. package/lib/module/components/UnifiedEventItem.js +23 -6
  34. package/lib/module/components/UnifiedEventItem.js.map +1 -1
  35. package/lib/module/components/UnifiedEventList.js +13 -1
  36. package/lib/module/components/UnifiedEventList.js.map +1 -1
  37. package/lib/module/hooks/useUnifiedEvents.js +120 -119
  38. package/lib/module/hooks/useUnifiedEvents.js.map +1 -1
  39. package/lib/module/index.js +5 -0
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/stores/unifiedEventStore.js +54 -1
  42. package/lib/module/stores/unifiedEventStore.js.map +1 -1
  43. package/lib/module/utils/autoDiscoverEventSources.js +54 -0
  44. package/lib/module/utils/autoDiscoverEventSources.js.map +1 -1
  45. package/lib/module/utils/badgeSelectionStorage.js +34 -0
  46. package/lib/module/utils/badgeSelectionStorage.js.map +1 -1
  47. package/lib/module/utils/testIDs.js +83 -0
  48. package/lib/module/utils/testIDs.js.map +1 -0
  49. package/lib/typescript/components/EventsCopySettingsView.d.ts.map +1 -1
  50. package/lib/typescript/components/EventsModal.d.ts.map +1 -1
  51. package/lib/typescript/components/UnifiedEventDetail.d.ts.map +1 -1
  52. package/lib/typescript/components/UnifiedEventFilters.d.ts.map +1 -1
  53. package/lib/typescript/components/UnifiedEventItem.d.ts.map +1 -1
  54. package/lib/typescript/components/UnifiedEventList.d.ts.map +1 -1
  55. package/lib/typescript/hooks/useUnifiedEvents.d.ts +10 -1
  56. package/lib/typescript/hooks/useUnifiedEvents.d.ts.map +1 -1
  57. package/lib/typescript/index.d.ts +1 -0
  58. package/lib/typescript/index.d.ts.map +1 -1
  59. package/lib/typescript/stores/unifiedEventStore.d.ts +13 -0
  60. package/lib/typescript/stores/unifiedEventStore.d.ts.map +1 -1
  61. package/lib/typescript/utils/autoDiscoverEventSources.d.ts.map +1 -1
  62. package/lib/typescript/utils/badgeSelectionStorage.d.ts +9 -0
  63. package/lib/typescript/utils/badgeSelectionStorage.d.ts.map +1 -1
  64. package/lib/typescript/utils/testIDs.d.ts +45 -0
  65. package/lib/typescript/utils/testIDs.d.ts.map +1 -0
  66. package/package.json +7 -8
  67. package/src/components/EventsCopySettingsView.tsx +0 -781
  68. package/src/components/EventsModal.tsx +0 -537
  69. package/src/components/ReactQueryEventDetail.tsx +0 -418
  70. package/src/components/UnifiedEventDetail.tsx +0 -596
  71. package/src/components/UnifiedEventFilters.tsx +0 -226
  72. package/src/components/UnifiedEventItem.tsx +0 -467
  73. package/src/components/UnifiedEventList.tsx +0 -216
  74. package/src/components/UnifiedEventViewer.tsx +0 -133
  75. package/src/hooks/useUnifiedEvents.ts +0 -573
  76. package/src/index.tsx +0 -128
  77. package/src/preset.tsx +0 -57
  78. package/src/sources/sourceIds.ts +0 -25
  79. package/src/stores/unifiedEventStore.ts +0 -686
  80. package/src/sync/__tests__/eventsSyncAdapter.test.ts +0 -471
  81. package/src/sync/eventsSyncAdapter.ts +0 -391
  82. package/src/types/copySettings.ts +0 -299
  83. package/src/types/index.ts +0 -101
  84. package/src/utils/autoDiscoverEventSources.ts +0 -1087
  85. package/src/utils/badgeSelectionStorage.ts +0 -81
  86. package/src/utils/copySettingsStorage.ts +0 -61
  87. package/src/utils/correlationUtils.ts +0 -146
  88. package/src/utils/eventExportFormatter.ts +0 -2066
  89. package/src/utils/eventTransformers.ts +0 -567
@@ -1,573 +0,0 @@
1
- /**
2
- * useUnifiedEvents Hook
3
- *
4
- * Main hook for consuming unified events from all sources.
5
- * Automatically discovers and subscribes to available event sources.
6
- */
7
-
8
- import { useState, useEffect, useCallback, useMemo, useRef } from "react";
9
- import {
10
- useFeatureGate,
11
- subscribeToSubscriberCountChanges,
12
- isDevToolsStorageKey,
13
- useIgnoredPatterns,
14
- isUrlIgnored,
15
- type IgnoredPattern,
16
- useLimit,
17
- } from "@buoy-gg/shared-ui";
18
- import type { UnifiedEvent, EventSource, SourceInfo } from "../types";
19
- import {
20
- subscribe,
21
- subscribeToStorage,
22
- subscribeToRedux,
23
- subscribeToNetwork,
24
- subscribeToReactQuery,
25
- subscribeToRoutes,
26
- subscribeToZustand,
27
- subscribeToJotai,
28
- subscribeToRender,
29
- unsubscribeFromStorage,
30
- unsubscribeFromRedux,
31
- unsubscribeFromNetwork,
32
- unsubscribeFromReactQuery,
33
- unsubscribeFromRoutes,
34
- unsubscribeFromZustand,
35
- unsubscribeFromJotai,
36
- unsubscribeFromRender,
37
- getSourceCounts,
38
- clearEvents as clearStoreEvents,
39
- getAvailableEventSources,
40
- getEvents,
41
- getSubscriberCounts,
42
- } from "../stores/unifiedEventStore";
43
- import {
44
- saveEnabledSources,
45
- loadEnabledSources,
46
- saveCapturingState,
47
- loadCapturingState,
48
- } from "../utils/badgeSelectionStorage";
49
- import { getSourceDisplayConfig } from "../utils/autoDiscoverEventSources";
50
-
51
- /** Network hosts used internally by Buoy dev tools */
52
- const BUOY_INTERNAL_HOSTS = ["api.keygen.sh"];
53
-
54
- /**
55
- * Check if an event is generated by Buoy's own dev tools (internal housekeeping).
56
- * These are filtered out by default so users only see their app's events.
57
- */
58
- function isBuoyInternalEvent(event: UnifiedEvent): boolean {
59
- const original = event.originalEvent as Record<string, any> | undefined;
60
- if (!original) return false;
61
-
62
- // Storage events: check if the key belongs to dev tools (@react_buoy prefix)
63
- if (event.source === "storage-async" || event.source === "storage-mmkv") {
64
- const key = original.data?.key || original.key;
65
- if (key && isDevToolsStorageKey(key)) return true;
66
-
67
- // Multi-key operations: check if ALL keys are dev tool keys
68
- const keys = original.data?.keys || original.data?.pairs?.map((p: [string, unknown]) => p[0]);
69
- if (keys && keys.length > 0 && keys.every((k: string) => isDevToolsStorageKey(k))) return true;
70
- }
71
-
72
- // Network events: check if the host/URL matches Buoy's internal APIs
73
- if (event.source === "network") {
74
- const host = original.host || "";
75
- const url = original.url || "";
76
- for (const internalHost of BUOY_INTERNAL_HOSTS) {
77
- if (host.includes(internalHost) || url.includes(internalHost)) return true;
78
- }
79
- }
80
-
81
- return false;
82
- }
83
-
84
- /**
85
- * Check whether a network event should be hidden because its URL matches one of
86
- * the user's shared ignored-domain/URL patterns (the same store the Network tool
87
- * writes to). Non-network events are never affected.
88
- */
89
- function isNetworkEventIgnored(
90
- event: UnifiedEvent,
91
- ignoredPatterns: IgnoredPattern[]
92
- ): boolean {
93
- if (event.source !== "network" || ignoredPatterns.length === 0) return false;
94
- const url = (event.originalEvent as { url?: string } | undefined)?.url ?? "";
95
- return isUrlIgnored(url, ignoredPatterns);
96
- }
97
-
98
- /**
99
- * Match an event against the header search query. Searches the two fields the
100
- * row actually renders (title/subtitle) plus a network event's full URL — the
101
- * title only carries the path, so a query for the host or a query-string value
102
- * would otherwise miss. `query` must already be lowercased and trimmed.
103
- */
104
- function matchesSearch(event: UnifiedEvent, query: string): boolean {
105
- if (event.title.toLowerCase().includes(query)) return true;
106
- if (event.subtitle.toLowerCase().includes(query)) return true;
107
- const url = (event.originalEvent as { url?: unknown } | undefined)?.url;
108
- return typeof url === "string" && url.toLowerCase().includes(query);
109
- }
110
-
111
- /**
112
- * All possible sources for display
113
- */
114
- const ALL_DISPLAY_SOURCES: EventSource[] = [
115
- "storage-async",
116
- "redux",
117
- "network",
118
- "react-query-query",
119
- "react-query-mutation",
120
- "route",
121
- "zustand",
122
- "jotai",
123
- "render",
124
- ];
125
-
126
- /**
127
- * Sources enabled by default on first load.
128
- * "render" is excluded because high-frequency render tracking can cause
129
- * performance issues or crashes in unoptimized apps.
130
- */
131
- const DEFAULT_ENABLED_SOURCES: EventSource[] = ALL_DISPLAY_SOURCES.filter(
132
- (s) => s !== "render"
133
- );
134
-
135
- /**
136
- * Map display sources to actual event sources they should match
137
- */
138
- const SOURCE_TO_EVENT_SOURCES: Record<EventSource, EventSource[]> = {
139
- "storage-async": ["storage-async", "storage-mmkv"],
140
- "storage-mmkv": ["storage-mmkv"],
141
- redux: ["redux"],
142
- network: ["network"],
143
- "react-query": ["react-query", "react-query-query"],
144
- "react-query-query": ["react-query", "react-query-query"],
145
- "react-query-mutation": ["react-query-mutation"],
146
- route: ["route"],
147
- zustand: ["zustand"],
148
- jotai: ["jotai"],
149
- render: ["render"],
150
- };
151
-
152
-
153
- export interface UseUnifiedEventsResult {
154
- events: UnifiedEvent[];
155
- filteredEvents: UnifiedEvent[];
156
- availableSources: SourceInfo[];
157
- enabledSources: Set<EventSource>;
158
- /** Header search query (matches title, subtitle and network URL) */
159
- searchText: string;
160
- setSearchText: (text: string) => void;
161
- toggleSource: (source: EventSource) => void;
162
- enableAllSources: () => void;
163
- clearEvents: () => void;
164
- totalCount: number;
165
- filteredCount: number;
166
- isCapturing: boolean;
167
- startCapturing: () => void;
168
- stopCapturing: () => void;
169
- toggleCapturing: () => void;
170
- /** Which sources are actually available (packages installed) */
171
- discoveredSources: Set<EventSource>;
172
- /** Number of events hidden due to free tier limit */
173
- hiddenEventsCount: number;
174
- /** Whether user is on Pro plan */
175
- isPro: boolean;
176
- /** Total number of subscribers across all event stores (for debugging) */
177
- totalSubscriberCount: number;
178
- }
179
-
180
- export function useUnifiedEvents(): UseUnifiedEventsResult {
181
- const { isPro } = useFeatureGate();
182
- const eventLimit = useLimit("events.entries");
183
- // Shared ignored-domain/URL patterns (same store as the Network tool). Network
184
- // events matching these are hidden from the events list too, keeping both
185
- // tools' filtering perfectly in sync.
186
- const { patterns: ignoredPatterns } = useIgnoredPatterns();
187
- const [events, setEvents] = useState<UnifiedEvent[]>([]);
188
- const [enabledSources, setEnabledSources] = useState<Set<EventSource>>(
189
- () => new Set(DEFAULT_ENABLED_SOURCES)
190
- );
191
- const [isCapturing, setIsCapturing] = useState(true);
192
- const [searchText, setSearchText] = useState("");
193
- const isStateRestoredRef = useRef(false);
194
-
195
- // Get discovered sources (which packages are installed).
196
- // Held in state, not a mount-only memo, because in remote mirror mode
197
- // (desktop dashboard) the device's available sources arrive asynchronously
198
- // via setRemoteAvailableSources() — after first paint. We refresh this from
199
- // the store's notify path below so the filter badge bar appears once the
200
- // first device snapshot lands. The reference is kept stable while the set is
201
- // unchanged so dependent memos/effects don't re-run on every event.
202
- const [discoveredSources, setDiscoveredSources] = useState<Set<EventSource>>(
203
- () => getAvailableEventSources()
204
- );
205
-
206
- // Subscribe to subscriber count changes for instant UI updates (TanStack Query pattern)
207
- const [subscriberCountVersion, setSubscriberCountVersion] = useState(0);
208
- useEffect(() => {
209
- return subscribeToSubscriberCountChanges(() => {
210
- setSubscriberCountVersion((v) => v + 1);
211
- });
212
- }, []);
213
-
214
- // Get available display sources (only show sources for installed packages)
215
- const availableDisplaySources = useMemo(() => {
216
- return ALL_DISPLAY_SOURCES.filter((displaySource) => {
217
- const eventSources = SOURCE_TO_EVENT_SOURCES[displaySource] || [displaySource];
218
- // Check if any of the event sources for this display source are available
219
- return eventSources.some((es) => discoveredSources.has(es));
220
- });
221
- }, [discoveredSources]);
222
-
223
- // Subscribe to store changes (always subscribe to get events when they come).
224
- // Also refresh discoveredSources here: in remote mirror mode the device's
225
- // availability is set right before replaceEvents() fires this listener, so
226
- // this is where the badge bar first learns which sources exist. Keep the
227
- // Set reference stable when membership is unchanged to avoid re-running the
228
- // availableDisplaySources memo / restore-state effect on every event.
229
- useEffect(() => {
230
- // Frame-coalesced: the aggregator hears EVERY tool's emissions, so
231
- // bursts previously produced one whole-modal commit per event (see
232
- // network tool-bench 2026-07-06 for the measured pattern).
233
- let rafId: number | null = null;
234
- const unsubscribe = subscribe(() => {
235
- if (rafId != null) return;
236
- rafId = requestAnimationFrame(() => {
237
- rafId = null;
238
- applyLatest();
239
- });
240
- });
241
- const applyLatest = () => {
242
- const newEvents = getEvents();
243
- setEvents(newEvents);
244
- setDiscoveredSources((prev) => {
245
- const next = getAvailableEventSources();
246
- if (prev.size === next.size && [...next].every((s) => prev.has(s))) {
247
- return prev;
248
- }
249
- return new Set(next);
250
- });
251
- };
252
- return () => {
253
- unsubscribe();
254
- if (rafId != null) cancelAnimationFrame(rafId);
255
- };
256
- }, []);
257
-
258
- // Restore saved state on mount (badge selection + capturing state)
259
- useEffect(() => {
260
- const restoreState = async () => {
261
- // Load badge selection
262
- const savedSources = await loadEnabledSources();
263
- let sourcesToEnable: Set<EventSource>;
264
-
265
- // Default enabled = available sources minus those excluded by default (e.g. render)
266
- const defaultEnabledAvailable = availableDisplaySources.filter(
267
- (s) => DEFAULT_ENABLED_SOURCES.includes(s)
268
- );
269
-
270
- if (savedSources && savedSources.length > 0) {
271
- // Filter to only include valid sources that still exist and are available
272
- const validSources = savedSources.filter(
273
- (s) => availableDisplaySources.includes(s)
274
- );
275
- if (validSources.length > 0) {
276
- sourcesToEnable = new Set(validSources);
277
- } else {
278
- // If no saved sources are valid, use defaults
279
- sourcesToEnable = new Set(defaultEnabledAvailable);
280
- }
281
- } else {
282
- // No saved state - use defaults (render disabled)
283
- sourcesToEnable = new Set(defaultEnabledAvailable);
284
- }
285
-
286
- setEnabledSources(sourcesToEnable);
287
-
288
- // Load capturing state (default to true if not saved)
289
- const savedCapturing = await loadCapturingState();
290
- const shouldCapture = savedCapturing !== null ? savedCapturing : true;
291
- setIsCapturing(shouldCapture);
292
-
293
- // Start capturing if enabled - only subscribe to enabled sources
294
- if (shouldCapture) {
295
- if (sourcesToEnable.has("storage-async")) subscribeToStorage();
296
- if (sourcesToEnable.has("redux")) subscribeToRedux();
297
- if (sourcesToEnable.has("network")) subscribeToNetwork();
298
- if (sourcesToEnable.has("react-query-query") || sourcesToEnable.has("react-query-mutation")) {
299
- subscribeToReactQuery();
300
- }
301
- if (sourcesToEnable.has("route")) subscribeToRoutes();
302
- if (sourcesToEnable.has("zustand")) subscribeToZustand();
303
- if (sourcesToEnable.has("jotai")) subscribeToJotai();
304
- if (sourcesToEnable.has("render")) subscribeToRender();
305
- }
306
-
307
- isStateRestoredRef.current = true;
308
- };
309
- restoreState();
310
- }, [availableDisplaySources]);
311
-
312
- // Persist enabled sources whenever they change (after initial restoration)
313
- useEffect(() => {
314
- if (!isStateRestoredRef.current) {
315
- return;
316
- }
317
- saveEnabledSources(Array.from(enabledSources));
318
- }, [enabledSources]);
319
-
320
- // Persist capturing state whenever it changes (after initial restoration)
321
- useEffect(() => {
322
- if (!isStateRestoredRef.current) {
323
- return;
324
- }
325
- saveCapturingState(isCapturing);
326
- }, [isCapturing]);
327
-
328
- // Build set of all event sources that should be shown
329
- const allowedEventSources = useMemo(() => {
330
- const allowed = new Set<EventSource>();
331
- enabledSources.forEach((displaySource) => {
332
- const eventSources = SOURCE_TO_EVENT_SOURCES[displaySource];
333
- if (eventSources) {
334
- eventSources.forEach((s) => allowed.add(s));
335
- }
336
- });
337
- return allowed;
338
- }, [enabledSources]);
339
-
340
- const normalizedSearch = searchText.trim().toLowerCase();
341
-
342
- // Filter events by enabled sources and the header search, exclude Buoy
343
- // internal events, and hide network events matching the shared
344
- // ignored-domain/URL patterns.
345
- const allFilteredEvents = useMemo(() => {
346
- if (allowedEventSources.size === 0) {
347
- return [];
348
- }
349
- return events.filter(
350
- (event) =>
351
- allowedEventSources.has(event.source) &&
352
- !isBuoyInternalEvent(event) &&
353
- !isNetworkEventIgnored(event, ignoredPatterns) &&
354
- (normalizedSearch === "" || matchesSearch(event, normalizedSearch))
355
- );
356
- }, [events, allowedEventSources, ignoredPatterns, normalizedSearch]);
357
-
358
- // Pro is Infinity here, so slice() returns everything and the hidden count
359
- // floors at 0 — no tier branching needed at the call site.
360
- const filteredEvents = useMemo(
361
- () => allFilteredEvents.slice(0, eventLimit),
362
- [allFilteredEvents, eventLimit]
363
- );
364
-
365
- const hiddenEventsCount = useMemo(
366
- () => Math.max(0, allFilteredEvents.length - eventLimit),
367
- [allFilteredEvents, eventLimit]
368
- );
369
-
370
- // Get all available sources with counts, sorted: enabled first, disabled last
371
- const availableSources = useMemo((): SourceInfo[] => {
372
- const counts = getSourceCounts();
373
- const subscriberCounts = getSubscriberCounts();
374
-
375
- // Build a map from source ID to subscriber count
376
- const subscriberCountBySourceId: Record<string, number> = {};
377
- for (const source of subscriberCounts.sources) {
378
- subscriberCountBySourceId[source.sourceId] = source.counts.total;
379
- }
380
-
381
- // Map display source to store source ID
382
- const displaySourceToStoreId: Record<EventSource, string> = {
383
- "storage-async": "storage",
384
- "storage-mmkv": "storage",
385
- redux: "redux",
386
- network: "network",
387
- "react-query": "react-query",
388
- "react-query-query": "react-query",
389
- "react-query-mutation": "react-query",
390
- route: "route-events",
391
- zustand: "zustand",
392
- jotai: "jotai",
393
- render: "render",
394
- };
395
-
396
- const sources = availableDisplaySources.map((source) => {
397
- const eventSources = SOURCE_TO_EVENT_SOURCES[source] || [source];
398
- const totalCount = eventSources.reduce((sum, s) => sum + (counts[s] || 0), 0);
399
- const displayConfig = getSourceDisplayConfig(source);
400
- const storeId = displaySourceToStoreId[source];
401
- // Only set subscriberCount if the source has subscriber tracking
402
- // (undefined means no tracking, vs 0 which means tracked but no subscribers)
403
- const subscriberCount = storeId && storeId in subscriberCountBySourceId
404
- ? subscriberCountBySourceId[storeId]
405
- : undefined;
406
-
407
- return {
408
- source,
409
- ...displayConfig,
410
- count: totalCount,
411
- enabled: enabledSources.has(source),
412
- subscriberCount,
413
- };
414
- });
415
-
416
- // Sort: enabled first, then disabled
417
- return sources.sort((a, b) => {
418
- if (a.enabled && !b.enabled) return -1;
419
- if (!a.enabled && b.enabled) return 1;
420
- return 0;
421
- });
422
- }, [events, enabledSources, availableDisplaySources, subscriberCountVersion]);
423
-
424
- const toggleSource = useCallback((source: EventSource) => {
425
- setEnabledSources((prev) => {
426
- const next = new Set(prev);
427
- const wasEnabled = next.has(source);
428
-
429
- if (wasEnabled) {
430
- next.delete(source);
431
- // Unsubscribe from the source
432
- switch (source) {
433
- case "storage-async":
434
- unsubscribeFromStorage();
435
- break;
436
- case "redux":
437
- unsubscribeFromRedux();
438
- break;
439
- case "network":
440
- unsubscribeFromNetwork();
441
- break;
442
- case "react-query-query":
443
- case "react-query-mutation":
444
- unsubscribeFromReactQuery();
445
- break;
446
- case "route":
447
- unsubscribeFromRoutes();
448
- break;
449
- case "zustand":
450
- unsubscribeFromZustand();
451
- break;
452
- case "jotai":
453
- unsubscribeFromJotai();
454
- break;
455
- case "render":
456
- unsubscribeFromRender();
457
- break;
458
- }
459
- } else {
460
- next.add(source);
461
- // Subscribe to the source (only if capturing is active)
462
- if (isCapturing) {
463
- switch (source) {
464
- case "storage-async":
465
- subscribeToStorage();
466
- break;
467
- case "redux":
468
- subscribeToRedux();
469
- break;
470
- case "network":
471
- subscribeToNetwork();
472
- break;
473
- case "react-query-query":
474
- case "react-query-mutation":
475
- subscribeToReactQuery();
476
- break;
477
- case "route":
478
- subscribeToRoutes();
479
- break;
480
- case "zustand":
481
- subscribeToZustand();
482
- break;
483
- case "jotai":
484
- subscribeToJotai();
485
- break;
486
- case "render":
487
- subscribeToRender();
488
- break;
489
- }
490
- }
491
- }
492
-
493
- return next;
494
- });
495
- }, [isCapturing]);
496
-
497
- const enableAllSources = useCallback(() => {
498
- setEnabledSources(new Set(availableDisplaySources));
499
- }, [availableDisplaySources]);
500
-
501
- const clearEvents = useCallback(() => {
502
- clearStoreEvents();
503
- }, []);
504
-
505
- const startCapturing = useCallback(() => {
506
- // Only subscribe to sources that are enabled
507
- if (enabledSources.has("storage-async")) subscribeToStorage();
508
- if (enabledSources.has("redux")) subscribeToRedux();
509
- if (enabledSources.has("network")) subscribeToNetwork();
510
- if (enabledSources.has("react-query-query") || enabledSources.has("react-query-mutation")) {
511
- subscribeToReactQuery();
512
- }
513
- if (enabledSources.has("route")) subscribeToRoutes();
514
- if (enabledSources.has("zustand")) subscribeToZustand();
515
- if (enabledSources.has("jotai")) subscribeToJotai();
516
- if (enabledSources.has("render")) subscribeToRender();
517
- setIsCapturing(true);
518
- }, [enabledSources]);
519
-
520
- const stopCapturing = useCallback(() => {
521
- // Release only THIS hook's enabled sources (mirrors startCapturing). Source
522
- // subscriptions are ref-counted in the store, so this won't yank sources a
523
- // remote dashboard consumer is still watching (vs the old unsubscribeAll
524
- // hard reset, which tore down everyone's).
525
- if (enabledSources.has("storage-async")) unsubscribeFromStorage();
526
- if (enabledSources.has("redux")) unsubscribeFromRedux();
527
- if (enabledSources.has("network")) unsubscribeFromNetwork();
528
- if (
529
- enabledSources.has("react-query-query") ||
530
- enabledSources.has("react-query-mutation")
531
- ) {
532
- unsubscribeFromReactQuery();
533
- }
534
- if (enabledSources.has("route")) unsubscribeFromRoutes();
535
- if (enabledSources.has("zustand")) unsubscribeFromZustand();
536
- if (enabledSources.has("jotai")) unsubscribeFromJotai();
537
- if (enabledSources.has("render")) unsubscribeFromRender();
538
- setIsCapturing(false);
539
- }, [enabledSources]);
540
-
541
- const toggleCapturing = useCallback(() => {
542
- if (isCapturing) {
543
- stopCapturing();
544
- } else {
545
- startCapturing();
546
- }
547
- }, [isCapturing, startCapturing, stopCapturing]);
548
-
549
- // Get subscriber counts (recalculates on every render, but it's a cheap operation)
550
- const totalSubscriberCount = getSubscriberCounts().totalSubscribers;
551
-
552
- return {
553
- events,
554
- filteredEvents,
555
- availableSources,
556
- enabledSources,
557
- searchText,
558
- setSearchText,
559
- toggleSource,
560
- enableAllSources,
561
- clearEvents,
562
- totalCount: events.length,
563
- filteredCount: filteredEvents.length,
564
- isCapturing,
565
- startCapturing,
566
- stopCapturing,
567
- toggleCapturing,
568
- discoveredSources,
569
- hiddenEventsCount,
570
- isPro,
571
- totalSubscriberCount,
572
- };
573
- }
package/src/index.tsx DELETED
@@ -1,128 +0,0 @@
1
- /**
2
- * @buoy-gg/events
3
- *
4
- * Unified event timeline for all DevTools sources.
5
- * Shows events from Storage, Redux, Network, React Query, etc.
6
- * in a single chronological view.
7
- *
8
- * PUBLIC API - Only these exports are supported for external use.
9
- * Internal stores and subscription mechanisms are not exported to prevent
10
- * bypassing the tool's intended usage patterns.
11
- */
12
-
13
- // =============================================================================
14
- // PRESET (Primary entry point for users)
15
- // =============================================================================
16
- export { eventsToolPreset, createEventsTool } from "./preset";
17
-
18
- // =============================================================================
19
- // MAIN COMPONENT
20
- // =============================================================================
21
- export { UnifiedEventViewer } from "./components/UnifiedEventViewer";
22
- // `EventsToolView` is the same tool rendered inline (header bar + body)
23
- // instead of inside a JsModal — for hosts that show tools in a panel.
24
- export { EventsModal, EventsToolView } from "./components/EventsModal";
25
- // The per-tool detail pages a bundled host must inject — see UnifiedEventDetail.
26
- export type { OptionalDetailComponents } from "./components/UnifiedEventDetail";
27
-
28
- // =============================================================================
29
- // EXTERNAL SYNC (Adapter for @buoy-gg/external-sync's useExternalSync)
30
- // =============================================================================
31
- export { eventsSyncAdapter } from "./sync/eventsSyncAdapter";
32
-
33
- // =============================================================================
34
- // HOOKS (For consuming event data)
35
- // =============================================================================
36
- export { useUnifiedEvents } from "./hooks/useUnifiedEvents";
37
- export type { UseUnifiedEventsResult } from "./hooks/useUnifiedEvents";
38
-
39
- // =============================================================================
40
- // TYPES
41
- // =============================================================================
42
- export type {
43
- UnifiedEvent,
44
- EventSource,
45
- EventStatus,
46
- EventFilter,
47
- SourceInfo,
48
- UnifiedEventListener,
49
- EventsCopySettings,
50
- CopyPresetName,
51
- } from "./types";
52
-
53
- // =============================================================================
54
- // COPY SETTINGS (Configuration types and presets)
55
- // =============================================================================
56
- export {
57
- DEFAULT_COPY_SETTINGS,
58
- COPY_PRESETS,
59
- PRESET_METADATA,
60
- detectActivePreset,
61
- } from "./types/copySettings";
62
-
63
- // =============================================================================
64
- // UI COMPONENTS (For custom implementations)
65
- // =============================================================================
66
- export { UnifiedEventItem } from "./components/UnifiedEventItem";
67
- export { UnifiedEventList } from "./components/UnifiedEventList";
68
- export { UnifiedEventFilters } from "./components/UnifiedEventFilters";
69
- export { UnifiedEventDetail } from "./components/UnifiedEventDetail";
70
- export { ReactQueryEventDetail } from "./components/ReactQueryEventDetail";
71
- export { EventsCopySettingsView } from "./components/EventsCopySettingsView";
72
-
73
- // =============================================================================
74
- // CORRELATION UTILITIES (For linking related events)
75
- // =============================================================================
76
- export {
77
- findRelatedEvents,
78
- hasRelatedEvents,
79
- getRelatedEventsCount,
80
- buildCorrelationCountMap,
81
- getCorrelationGroup,
82
- getCorrelationLabel,
83
- getCorrelationColor,
84
- } from "./utils/correlationUtils";
85
-
86
- // =============================================================================
87
- // EXPORT UTILITIES (For generating formatted exports)
88
- // =============================================================================
89
- export {
90
- generateExport,
91
- generateMarkdownExport,
92
- generateJsonExport,
93
- generatePlaintextExport,
94
- generateMermaidExport,
95
- estimateExportSize,
96
- getExportSummary,
97
- filterEvents,
98
- } from "./utils/eventExportFormatter";
99
- export type { ExportSummary } from "./utils/eventExportFormatter";
100
-
101
- // =============================================================================
102
- // COPY SETTINGS STORAGE (For persisting export preferences)
103
- // =============================================================================
104
- export {
105
- loadCopySettings,
106
- saveCopySettings,
107
- clearCopySettings,
108
- } from "./utils/copySettingsStorage";
109
-
110
- // =============================================================================
111
- // INTERNAL EXPORTS (For @buoy-gg/* packages only - not part of public API)
112
- // These are NOT exported to prevent users from bypassing the unified event
113
- // system. Event subscription should go through the proper tool integration.
114
- // =============================================================================
115
- /** @internal - Remote mirror mode only (desktop dashboard): replaceEvents /
116
- * onClear / setRemoteAvailableSources. Do not use for event subscription. */
117
- export { unifiedEventStore } from "./stores/unifiedEventStore";
118
- // NOTE: The following are intentionally NOT exported:
119
- // - subscribeToStorage, unsubscribeFromStorage (internal subscription)
120
- // - subscribeToRedux, unsubscribeFromRedux (internal subscription)
121
- // - subscribeToNetwork, unsubscribeFromNetwork (internal subscription)
122
- // - subscribeToReactQuery, unsubscribeFromReactQuery (internal subscription)
123
- // - subscribeToRoutes, unsubscribeFromRoutes (internal subscription)
124
- // - getEvents, getActiveSources, getSourceCounts (internal store operations)
125
- // - clearEvents, subscribe, getEventCount (internal store operations)
126
-
127
- // Note: For subscriber count notifications, use @buoy-gg/shared-ui:
128
- // import { notifySubscriberCountChange, subscribeToSubscriberCountChanges } from "@buoy-gg/shared-ui";