@buoy-gg/events 7.0.28 → 7.0.30

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.
@@ -1,536 +0,0 @@
1
- /**
2
- * EventsModal
3
- *
4
- * Modal wrapper for the unified events timeline.
5
- * Uses JsModal for consistent bottom sheet behavior.
6
- */
7
-
8
- import {
9
- View,
10
- StyleSheet,
11
- TouchableOpacity,
12
- Text,
13
- TextInput,
14
- Alert,
15
- } from "react-native";
16
- import {
17
- useState,
18
- useCallback,
19
- useEffect,
20
- useRef,
21
- type ComponentType,
22
- type ReactNode,
23
- } from "react";
24
- import {
25
- JsModal,
26
- ModalHeader,
27
- buoyColors,
28
- night,
29
- Trash2,
30
- Copy,
31
- Search,
32
- X,
33
- devToolsStorageKeys,
34
- ToolbarCopyButton,
35
- UpgradeModal,
36
- PowerToggleButton,
37
- useSafeRouter,
38
- } from "@buoy-gg/shared-ui";
39
- import type { ModalMode } from "@buoy-gg/shared-ui";
40
- import { useUnifiedEvents } from "../hooks/useUnifiedEvents";
41
- import { UnifiedEventFilters } from "./UnifiedEventFilters";
42
- import { UnifiedEventList } from "./UnifiedEventList";
43
- import { UnifiedEventDetail } from "./UnifiedEventDetail";
44
- import type { OptionalDetailComponents } from "./UnifiedEventDetail";
45
- import { EventsCopySettingsView } from "./EventsCopySettingsView";
46
- import type { UnifiedEvent } from "../types";
47
-
48
- // Try to load TickProvider from network package for time refresh
49
- let TickProvider: ComponentType<{ children: ReactNode }> | null = null;
50
- try {
51
- // @ts-ignore - Dynamic import that may not exist
52
- const network = require("@buoy-gg/network");
53
- TickProvider = network.TickProvider;
54
- } catch {
55
- // Network package not installed, times won't auto-refresh
56
- }
57
-
58
- type ModalView = "list" | "detail" | "copySettings";
59
-
60
- interface EventsModalProps {
61
- visible: boolean;
62
- onClose: () => void;
63
- onBack?: () => void;
64
- onMinimize?: (modalState: unknown) => void;
65
- enableSharedModalDimensions?: boolean;
66
- /**
67
- * Render as a header-bar + body stack instead of inside `JsModal`, for hosts
68
- * that place tools in a panel rather than a modal (Buoy Desktop). Only the
69
- * shell differs — header, screens and state are shared. See `EventsToolView`.
70
- */
71
- inline?: boolean;
72
- /**
73
- * Controlled capture toggle. Omit and the tool drives its own store, which is
74
- * what the phone wants. The desktop passes its persisted capture store,
75
- * because there the toggle also has to stop the DEVICE streaming.
76
- */
77
- capturing?: boolean;
78
- onCapturingChange?: (capturing: boolean) => void;
79
- /**
80
- * Wraps the network-event detail page. The desktop dashboard uses it to
81
- * provide the body resolver, so payloads the device stripped from the sync
82
- * snapshot can be fetched on demand. Omit on device — bodies are already
83
- * local there.
84
- */
85
- networkDetailWrapper?: ComponentType<{ children: ReactNode }>;
86
- /**
87
- * Overrides for the per-tool detail pages `UnifiedEventDetail` renders when
88
- * you open a network or route event.
89
- *
90
- * ⚠️ NOT optional on the desktop. `UnifiedEventDetail` normally resolves these
91
- * with a runtime `require("@buoy-gg/network")`, which does not work in a
92
- * Vite/ESM bundle — omit them there and opening a network or route event
93
- * silently falls back to the generic renderer instead of the real tool page.
94
- */
95
- NetworkEventDetailViewComponent?: ComponentType<{
96
- event: unknown;
97
- ignoredPatterns?: Set<string>;
98
- onTogglePattern?: (value: string) => void;
99
- }>;
100
- RouteEventDetailComponent?: ComponentType<{
101
- event: unknown;
102
- visitNumber?: number;
103
- onNavigate?: (pathname: string) => void;
104
- }>;
105
- /**
106
- * Overrides for EVERY per-tool detail page — storage, redux, zustand, jotai
107
- * and renders as well as network and route. Same reason as the two above: the
108
- * runtime `require` that normally resolves them does not work in a bundled
109
- * host, so without these, opening one of those events falls back to the
110
- * generic renderer.
111
- */
112
- detailComponents?: Partial<OptionalDetailComponents>;
113
- }
114
-
115
- export function EventsModal({
116
- visible,
117
- onClose,
118
- onBack,
119
- onMinimize,
120
- enableSharedModalDimensions = false,
121
- inline = false,
122
- capturing: capturingProp,
123
- onCapturingChange,
124
- networkDetailWrapper,
125
- NetworkEventDetailViewComponent,
126
- RouteEventDetailComponent,
127
- detailComponents,
128
- }: EventsModalProps) {
129
- const router = useSafeRouter();
130
- const {
131
- filteredEvents,
132
- availableSources,
133
- toggleSource,
134
- clearEvents,
135
- totalCount,
136
- filteredCount,
137
- isCapturing: isCapturingLocal,
138
- toggleCapturing: toggleCapturingLocal,
139
- hiddenEventsCount,
140
- searchText,
141
- setSearchText,
142
- } = useUnifiedEvents();
143
-
144
- // Controlled when the host supplies both halves; otherwise the tool's own
145
- // store is the source of truth.
146
- const controlledCapture = capturingProp != null && onCapturingChange != null;
147
- const isCapturing = controlledCapture ? capturingProp : isCapturingLocal;
148
- const toggleCapturing = controlledCapture
149
- ? () => onCapturingChange(!capturingProp)
150
- : toggleCapturingLocal;
151
-
152
- const [currentView, setCurrentView] = useState<ModalView>("list");
153
- const [selectedEvent, setSelectedEvent] = useState<UnifiedEvent | null>(null);
154
- const [showUpgradeModal, setShowUpgradeModal] = useState(false);
155
- const [isSearchActive, setIsSearchActive] = useState(false);
156
- const searchInputRef = useRef<TextInput>(null);
157
-
158
- // Focus after the input has actually mounted (it replaces the title block).
159
- useEffect(() => {
160
- if (!isSearchActive) return;
161
- const frame = requestAnimationFrame(() => {
162
- searchInputRef.current?.focus();
163
- });
164
- return () => cancelAnimationFrame(frame);
165
- }, [isSearchActive]);
166
-
167
- const closeSearch = useCallback(() => {
168
- setIsSearchActive(false);
169
- setSearchText("");
170
- }, [setSearchText]);
171
-
172
- // Navigation handler for route events
173
- const handleNavigate = useCallback(
174
- (pathname: string) => {
175
- try {
176
- router.push(pathname as any);
177
- } catch (error) {
178
- Alert.alert("Navigation Error", String(error));
179
- }
180
- },
181
- [router]
182
- );
183
-
184
- const handleEventPress = useCallback((event: UnifiedEvent) => {
185
- setSelectedEvent(event);
186
- setCurrentView("detail");
187
- }, []);
188
-
189
- const handleBack = useCallback(() => {
190
- if (currentView === "detail") {
191
- setSelectedEvent(null);
192
- setCurrentView("list");
193
- } else if (currentView === "copySettings") {
194
- setCurrentView("list");
195
- }
196
- }, [currentView]);
197
-
198
- const handleOpenCopySettings = useCallback(() => {
199
- setCurrentView("copySettings");
200
- }, []);
201
-
202
- const handleModeChange = useCallback((_mode: ModalMode) => {
203
- // Mode changes handled by JsModal
204
- }, []);
205
-
206
- const persistenceKey = enableSharedModalDimensions
207
- ? devToolsStorageKeys.modal.root()
208
- : "buoy-events-modal";
209
-
210
- if (!visible) return null;
211
-
212
- const renderHeaderContent = () => {
213
- // Detail view header
214
- if (currentView === "detail" && selectedEvent) {
215
- const copyData = {
216
- source: selectedEvent.source,
217
- title: selectedEvent.title,
218
- subtitle: selectedEvent.subtitle,
219
- status: selectedEvent.status,
220
- timestamp: new Date(selectedEvent.timestamp).toISOString(),
221
- data: selectedEvent.originalEvent,
222
- };
223
- return (
224
- <ModalHeader>
225
- <ModalHeader.Navigation onBack={handleBack} />
226
- <ModalHeader.Content title={selectedEvent.title} />
227
- <ModalHeader.Actions>
228
- <ToolbarCopyButton value={copyData} />
229
- </ModalHeader.Actions>
230
- </ModalHeader>
231
- );
232
- }
233
-
234
- // Copy settings view header
235
- if (currentView === "copySettings") {
236
- return (
237
- <ModalHeader>
238
- <ModalHeader.Navigation onBack={handleBack} />
239
- <ModalHeader.Content title="Copy Settings" />
240
- </ModalHeader>
241
- );
242
- }
243
-
244
- // List view header (default)
245
- return (
246
- <ModalHeader>
247
- {onBack && <ModalHeader.Navigation onBack={onBack} />}
248
- <ModalHeader.Content title="">
249
- {isSearchActive ? (
250
- <View style={styles.headerSearchContainer}>
251
- <Search size={14} color={night.color.textSecondary} />
252
- <TextInput
253
- ref={searchInputRef}
254
- style={styles.headerSearchInput}
255
- placeholder="Search events..."
256
- placeholderTextColor={night.color.placeholder}
257
- value={searchText}
258
- onChangeText={setSearchText}
259
- onSubmitEditing={() => searchInputRef.current?.blur()}
260
- // Stay open while the query still filters the list — collapsing
261
- // it would hide why events are missing.
262
- onBlur={() => {
263
- if (searchText.length === 0) setIsSearchActive(false);
264
- }}
265
- accessibilityLabel="Search events"
266
- autoCapitalize="none"
267
- autoCorrect={false}
268
- returnKeyType="search"
269
- />
270
- <TouchableOpacity
271
- onPress={closeSearch}
272
- style={styles.headerSearchClear}
273
- accessibilityLabel="Close search"
274
- >
275
- <X size={14} color={night.color.textSecondary} />
276
- </TouchableOpacity>
277
- </View>
278
- ) : (
279
- <View style={styles.headerTitleContainer}>
280
- <Text style={styles.headerTitle}>Events</Text>
281
- <Text style={styles.headerSubtitle}>
282
- {totalCount} captured
283
- </Text>
284
- </View>
285
- )}
286
- </ModalHeader.Content>
287
- <ModalHeader.Actions>
288
- {!isSearchActive && (
289
- <TouchableOpacity
290
- onPress={() => setIsSearchActive(true)}
291
- style={[
292
- styles.headerActionButton,
293
- searchText.length > 0 && styles.headerActionButtonActive,
294
- ]}
295
- accessibilityLabel="Search events"
296
- >
297
- <Search
298
- size={14}
299
- color={
300
- searchText.length > 0
301
- ? night.color.accent
302
- : night.color.textSecondary
303
- }
304
- />
305
- </TouchableOpacity>
306
- )}
307
-
308
- <TouchableOpacity
309
- onPress={handleOpenCopySettings}
310
- style={[
311
- styles.headerActionButton,
312
- totalCount === 0 && styles.headerActionButtonDisabled,
313
- ]}
314
- disabled={totalCount === 0}
315
- accessibilityLabel="Copy events"
316
- >
317
- <Copy
318
- size={14}
319
- color={
320
- totalCount > 0
321
- ? night.color.textSecondary
322
- : night.color.textTertiary
323
- }
324
- />
325
- </TouchableOpacity>
326
-
327
- <PowerToggleButton
328
- isEnabled={isCapturing}
329
- onToggle={toggleCapturing}
330
- accessibilityLabel="Toggle event capture"
331
- />
332
-
333
- <TouchableOpacity
334
- onPress={clearEvents}
335
- style={[
336
- styles.headerActionButton,
337
- totalCount === 0 && styles.headerActionButtonDisabled,
338
- ]}
339
- disabled={totalCount === 0}
340
- accessibilityLabel="Clear events"
341
- >
342
- <Trash2
343
- size={14}
344
- color={
345
- totalCount > 0
346
- ? night.color.textSecondary
347
- : night.color.textTertiary
348
- }
349
- />
350
- </TouchableOpacity>
351
- </ModalHeader.Actions>
352
- </ModalHeader>
353
- );
354
- };
355
-
356
- const content = (
357
- <View style={styles.container}>
358
- {currentView === "copySettings" ? (
359
- <EventsCopySettingsView events={filteredEvents} />
360
- ) : currentView === "detail" && selectedEvent ? (
361
- <UnifiedEventDetail
362
- event={selectedEvent}
363
- onBack={handleBack}
364
- onNavigate={handleNavigate}
365
- networkDetailWrapper={networkDetailWrapper}
366
- NetworkEventDetailViewComponent={NetworkEventDetailViewComponent}
367
- RouteEventDetailComponent={RouteEventDetailComponent}
368
- detailComponents={detailComponents}
369
- />
370
- ) : (
371
- <>
372
- <UnifiedEventFilters
373
- availableSources={availableSources}
374
- onToggleSource={toggleSource}
375
- totalCount={totalCount}
376
- filteredCount={filteredCount}
377
- />
378
- <UnifiedEventList
379
- events={filteredEvents}
380
- selectedEventId={undefined}
381
- expandedEventId={undefined}
382
- onEventPress={handleEventPress}
383
- onNavigate={handleNavigate}
384
- isCapturing={isCapturing}
385
- hiddenEventsCount={hiddenEventsCount}
386
- searchText={searchText}
387
- onUpgradePress={() => setShowUpgradeModal(true)}
388
- />
389
- </>
390
- )}
391
- </View>
392
- );
393
-
394
- const body = TickProvider ? <TickProvider>{content}</TickProvider> : content;
395
-
396
- const upgradeModal = (<>
397
- <UpgradeModal
398
- visible={showUpgradeModal}
399
- onClose={() => setShowUpgradeModal(false)}
400
- featureName="Unlimited Events"
401
- description="View your complete event history to debug complex flows and track down issues."
402
- benefits={[
403
- "Unlimited event history (vs 25 events)",
404
- "Export events to Markdown, JSON, or plain text",
405
- "Share event flows with teammates",
406
- "Feed event context directly to AI assistants",
407
- ]}
408
- />
409
- </>);
410
-
411
- // The ONLY difference between the phone and the desktop dashboard is which
412
- // shell the header and body go in. Everything above this line is shared.
413
- if (inline) {
414
- return (
415
- <>
416
- <View style={styles.inlineRoot}>
417
- {/* Flex-less wrapper — `ModalHeader` is `flex: 1` for JsModal's
418
- ROW-direction header slot and would grow vertically here. */}
419
- <View style={styles.inlineHeader}>{renderHeaderContent()}</View>
420
- {body}
421
- </View>
422
- {upgradeModal}
423
- </>
424
- );
425
- }
426
-
427
- return (
428
- <>
429
- <JsModal
430
- visible={visible}
431
- onClose={onClose}
432
- onMinimize={onMinimize}
433
- persistenceKey={persistenceKey}
434
- header={{
435
- showToggleButton: true,
436
- customContent: renderHeaderContent(),
437
- }}
438
- onModeChange={handleModeChange}
439
- enablePersistence={true}
440
- initialMode="bottomSheet"
441
- enableGlitchEffects={true}
442
- styles={{}}
443
- disableScrollWrapper={true}
444
- >
445
- {body}
446
- </JsModal>
447
- {upgradeModal}
448
- </>
449
- );
450
- }
451
-
452
- const styles = StyleSheet.create({
453
- inlineRoot: {
454
- flex: 1,
455
- minHeight: 0,
456
- // Transparent so the desktop workbench's hoisted sky (one field spanning
457
- // sidebar + panel) shows through — the shell paints its base beneath it.
458
- backgroundColor: "transparent",
459
- },
460
- inlineHeader: {
461
- paddingHorizontal: 12,
462
- paddingVertical: 8,
463
- borderBottomWidth: 1,
464
- borderBottomColor: buoyColors.border,
465
- backgroundColor: buoyColors.card,
466
- },
467
- container: {
468
- flex: 1,
469
- // Transparent so JsModal's ToolBackground shows through (the modal paints opaque base beneath it).
470
- backgroundColor: "transparent",
471
- },
472
- headerTitleContainer: {
473
- flexDirection: "row",
474
- alignItems: "baseline",
475
- gap: 8,
476
- },
477
- headerTitle: {
478
- fontSize: 16,
479
- fontWeight: "600",
480
- color: night.color.text,
481
- },
482
- headerSubtitle: {
483
- fontSize: 12,
484
- color: night.color.textTertiary,
485
- },
486
- headerActionButton: {
487
- width: 32,
488
- height: 32,
489
- borderRadius: 8,
490
- backgroundColor: night.color.buttonSurface,
491
- borderWidth: 1,
492
- borderColor: night.color.border,
493
- alignItems: "center",
494
- justifyContent: "center",
495
- },
496
- headerActionButtonDisabled: {
497
- opacity: 0.55,
498
- },
499
- headerActionButtonActive: {
500
- backgroundColor: night.color.accentSoft,
501
- borderColor: night.color.accentBorderStrong,
502
- },
503
- headerSearchContainer: {
504
- flexDirection: "row",
505
- alignItems: "center",
506
- backgroundColor: night.color.surfaceElevated,
507
- borderRadius: night.radius.row,
508
- borderWidth: 1,
509
- borderColor: night.color.border,
510
- paddingHorizontal: 10,
511
- paddingVertical: 4,
512
- },
513
- headerSearchInput: {
514
- flex: 1,
515
- color: night.color.text,
516
- fontSize: 13,
517
- marginLeft: 6,
518
- paddingVertical: 2,
519
- },
520
- headerSearchClear: {
521
- marginLeft: 6,
522
- padding: 4,
523
- },
524
- });
525
-
526
- /**
527
- * The same events tool as `EventsModal`, rendered INLINE for hosts that place
528
- * tools in a panel rather than a modal. Exists so there is exactly one
529
- * implementation — the desktop dashboard used to ship its own copy of this
530
- * component's header and screen router.
531
- */
532
- export function EventsToolView(
533
- props: Omit<EventsModalProps, "visible" | "onClose" | "inline"> = {}
534
- ) {
535
- return <EventsModal {...props} inline visible onClose={() => {}} />;
536
- }