jazz-tools 0.20.1 → 0.20.3

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 (115) hide show
  1. package/.turbo/turbo-build.log +49 -49
  2. package/CHANGELOG.md +19 -6
  3. package/dist/{chunk-2OPP7KWV.js → chunk-Q5RNSSUM.js} +121 -22
  4. package/dist/chunk-Q5RNSSUM.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/inspector/{chunk-MCTB5ZJC.js → chunk-6JPVMI3V.js} +302 -182
  7. package/dist/inspector/chunk-6JPVMI3V.js.map +1 -0
  8. package/dist/inspector/{custom-element-5YWVZBWA.js → custom-element-WOQY2M4W.js} +1337 -206
  9. package/dist/inspector/custom-element-WOQY2M4W.js.map +1 -0
  10. package/dist/inspector/in-app.d.ts +1 -0
  11. package/dist/inspector/in-app.d.ts.map +1 -1
  12. package/dist/inspector/index.d.ts +1 -0
  13. package/dist/inspector/index.d.ts.map +1 -1
  14. package/dist/inspector/index.js +1044 -17
  15. package/dist/inspector/index.js.map +1 -1
  16. package/dist/inspector/pages/home.d.ts +4 -1
  17. package/dist/inspector/pages/home.d.ts.map +1 -1
  18. package/dist/inspector/pages/performance/PerformancePage.d.ts +7 -0
  19. package/dist/inspector/pages/performance/PerformancePage.d.ts.map +1 -0
  20. package/dist/inspector/pages/performance/SubscriptionDetailPanel.d.ts +8 -0
  21. package/dist/inspector/pages/performance/SubscriptionDetailPanel.d.ts.map +1 -0
  22. package/dist/inspector/pages/performance/SubscriptionRow.d.ts +11 -0
  23. package/dist/inspector/pages/performance/SubscriptionRow.d.ts.map +1 -0
  24. package/dist/inspector/pages/performance/Timeline.d.ts +12 -0
  25. package/dist/inspector/pages/performance/Timeline.d.ts.map +1 -0
  26. package/dist/inspector/pages/performance/helpers.d.ts +5 -0
  27. package/dist/inspector/pages/performance/helpers.d.ts.map +1 -0
  28. package/dist/inspector/pages/performance/index.d.ts +3 -0
  29. package/dist/inspector/pages/performance/index.d.ts.map +1 -0
  30. package/dist/inspector/pages/performance/types.d.ts +13 -0
  31. package/dist/inspector/pages/performance/types.d.ts.map +1 -0
  32. package/dist/inspector/pages/performance/usePerformanceEntries.d.ts +3 -0
  33. package/dist/inspector/pages/performance/usePerformanceEntries.d.ts.map +1 -0
  34. package/dist/inspector/register-custom-element.js +3 -1
  35. package/dist/inspector/register-custom-element.js.map +1 -1
  36. package/dist/inspector/standalone.js +1 -1
  37. package/dist/inspector/tests/pages/performance/PerformancePage.test.d.ts +2 -0
  38. package/dist/inspector/tests/pages/performance/PerformancePage.test.d.ts.map +1 -0
  39. package/dist/inspector/tests/pages/performance/SubscriptionDetailPanel.test.d.ts +2 -0
  40. package/dist/inspector/tests/pages/performance/SubscriptionDetailPanel.test.d.ts.map +1 -0
  41. package/dist/inspector/tests/pages/performance/SubscriptionRow.test.d.ts +2 -0
  42. package/dist/inspector/tests/pages/performance/SubscriptionRow.test.d.ts.map +1 -0
  43. package/dist/inspector/tests/pages/performance/Timeline.test.d.ts +2 -0
  44. package/dist/inspector/tests/pages/performance/Timeline.test.d.ts.map +1 -0
  45. package/dist/inspector/tests/pages/performance/helpers.test.d.ts +2 -0
  46. package/dist/inspector/tests/pages/performance/helpers.test.d.ts.map +1 -0
  47. package/dist/inspector/viewer/delete-local-data.d.ts.map +1 -1
  48. package/dist/inspector/viewer/header.d.ts +4 -2
  49. package/dist/inspector/viewer/header.d.ts.map +1 -1
  50. package/dist/inspector/viewer/page-stack.d.ts +3 -1
  51. package/dist/inspector/viewer/page-stack.d.ts.map +1 -1
  52. package/dist/react-core/hooks.d.ts +2 -2
  53. package/dist/react-core/hooks.d.ts.map +1 -1
  54. package/dist/react-core/index.js +50 -18
  55. package/dist/react-core/index.js.map +1 -1
  56. package/dist/react-core/subscription-provider.d.ts.map +1 -1
  57. package/dist/react-native-core/media/image.d.ts +1 -1
  58. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  59. package/dist/svelte/jazz.class.svelte.js +27 -22
  60. package/dist/testing.js +1 -1
  61. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  62. package/dist/tools/exports.d.ts +1 -1
  63. package/dist/tools/exports.d.ts.map +1 -1
  64. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
  65. package/dist/tools/subscribe/SubscriptionCache.d.ts +2 -2
  66. package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -1
  67. package/dist/tools/subscribe/SubscriptionScope.d.ts +19 -12
  68. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  69. package/dist/tools/subscribe/errorReporting.d.ts +6 -0
  70. package/dist/tools/subscribe/errorReporting.d.ts.map +1 -1
  71. package/dist/tools/subscribe/index.d.ts +4 -4
  72. package/dist/tools/subscribe/index.d.ts.map +1 -1
  73. package/dist/tools/subscribe/types.d.ts +48 -3
  74. package/dist/tools/subscribe/types.d.ts.map +1 -1
  75. package/dist/tools/subscribe/utils.d.ts +1 -1
  76. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  77. package/dist/tools/tests/SubscriptionScope.performance.test.d.ts +2 -0
  78. package/dist/tools/tests/SubscriptionScope.performance.test.d.ts.map +1 -0
  79. package/package.json +4 -4
  80. package/src/inspector/in-app.tsx +41 -3
  81. package/src/inspector/index.tsx +5 -1
  82. package/src/inspector/pages/home.tsx +26 -3
  83. package/src/inspector/pages/performance/PerformancePage.tsx +215 -0
  84. package/src/inspector/pages/performance/SubscriptionDetailPanel.tsx +182 -0
  85. package/src/inspector/pages/performance/SubscriptionRow.tsx +242 -0
  86. package/src/inspector/pages/performance/Timeline.tsx +513 -0
  87. package/src/inspector/pages/performance/helpers.ts +70 -0
  88. package/src/inspector/pages/performance/index.ts +2 -0
  89. package/src/inspector/pages/performance/types.ts +12 -0
  90. package/src/inspector/pages/performance/usePerformanceEntries.ts +53 -0
  91. package/src/inspector/register-custom-element.ts +3 -0
  92. package/src/inspector/tests/pages/performance/PerformancePage.test.tsx +83 -0
  93. package/src/inspector/tests/pages/performance/SubscriptionDetailPanel.test.tsx +68 -0
  94. package/src/inspector/tests/pages/performance/SubscriptionRow.test.tsx +93 -0
  95. package/src/inspector/tests/pages/performance/Timeline.test.tsx +57 -0
  96. package/src/inspector/tests/pages/performance/helpers.test.ts +91 -0
  97. package/src/inspector/viewer/delete-local-data.tsx +24 -5
  98. package/src/inspector/viewer/header.tsx +96 -17
  99. package/src/inspector/viewer/page-stack.tsx +22 -18
  100. package/src/react-core/hooks.ts +34 -4
  101. package/src/react-core/subscription-provider.tsx +17 -8
  102. package/src/svelte/jazz.class.svelte.ts +51 -33
  103. package/src/tools/coValues/interfaces.ts +3 -0
  104. package/src/tools/exports.ts +1 -0
  105. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +13 -0
  106. package/src/tools/subscribe/SubscriptionCache.ts +6 -4
  107. package/src/tools/subscribe/SubscriptionScope.ts +141 -23
  108. package/src/tools/subscribe/errorReporting.ts +1 -1
  109. package/src/tools/subscribe/index.ts +1 -1
  110. package/src/tools/subscribe/types.ts +62 -9
  111. package/src/tools/subscribe/utils.ts +2 -2
  112. package/src/tools/tests/SubscriptionScope.performance.test.ts +149 -0
  113. package/dist/chunk-2OPP7KWV.js.map +0 -1
  114. package/dist/inspector/chunk-MCTB5ZJC.js.map +0 -1
  115. package/dist/inspector/custom-element-5YWVZBWA.js.map +0 -1
@@ -0,0 +1,215 @@
1
+ import { styled } from "goober";
2
+ import { type CSSProperties, useMemo, useState, useDeferredValue } from "react";
3
+ import { CoID, RawCoValue } from "cojson";
4
+ import { useRouter } from "../../router/context.js";
5
+ import { Timeline } from "./Timeline.js";
6
+ import { SubscriptionRow } from "./SubscriptionRow.js";
7
+ import { SubscriptionDetailPanel } from "./SubscriptionDetailPanel.js";
8
+ import { usePerformanceEntries } from "./usePerformanceEntries.js";
9
+ import type { SubscriptionEntry } from "./types.js";
10
+ import { SubscriptionScope } from "jazz-tools";
11
+
12
+ // ============================================================================
13
+ // Styled Components
14
+ // ============================================================================
15
+
16
+ const Container = styled("div")`
17
+ display: flex;
18
+ flex-direction: column;
19
+ gap: 0.5rem;
20
+ padding: 1rem;
21
+ height: 100%;
22
+ min-height: 0;
23
+ `;
24
+
25
+ const MainLayout = styled("div")`
26
+ display: flex;
27
+ flex: 1;
28
+ min-height: 0;
29
+ gap: 1rem;
30
+ `;
31
+
32
+ const ListPanel = styled("div")`
33
+ flex: 1;
34
+ min-width: 0;
35
+ display: flex;
36
+ flex-direction: column;
37
+ `;
38
+
39
+ const Grid = styled("div")`
40
+ display: grid;
41
+ grid-template-columns:
42
+ minmax(100px, 150px)
43
+ minmax(150px, 1fr)
44
+ minmax(100px, 200px)
45
+ 80px;
46
+ grid-template-rows: min-content;
47
+ overflow-y: auto;
48
+ overflow-x: hidden;
49
+ flex: 1;
50
+ min-height: 0;
51
+ position: relative;
52
+ `;
53
+
54
+ const HeaderCell = styled("div")`
55
+ padding: 0.5rem;
56
+ font-size: 0.625rem;
57
+ font-weight: 600;
58
+ color: var(--j-neutral-500);
59
+ border-bottom: 1px solid var(--j-border-color);
60
+ text-transform: uppercase;
61
+ letter-spacing: 0.05em;
62
+ `;
63
+
64
+ const EmptyState = styled("div")`
65
+ text-align: center;
66
+ padding: 2rem;
67
+ color: var(--j-neutral-500);
68
+ font-size: 0.875rem;
69
+ `;
70
+
71
+ // ============================================================================
72
+ // Component
73
+ // ============================================================================
74
+
75
+ export interface PerformancePageProps {
76
+ onNavigate: () => void;
77
+ style?: CSSProperties;
78
+ }
79
+
80
+ export function PerformancePage({ onNavigate, style }: PerformancePageProps) {
81
+ const entries = usePerformanceEntries();
82
+ const [selectedRow, setSelectedRow] = useState<string | null>(null);
83
+ const [timeSelection, setTimeSelection] = useState<[number, number] | null>(
84
+ null,
85
+ );
86
+ const deferredSelection = useDeferredValue(timeSelection);
87
+ const { setPage } = useRouter();
88
+
89
+ const selectRow = (uuid: string) => {
90
+ setSelectedRow((prev) => (prev === uuid ? null : uuid));
91
+ };
92
+
93
+ const sortedEntries = useMemo(() => {
94
+ return [...entries].sort((a, b) => a.startTime - b.startTime);
95
+ }, [entries]);
96
+
97
+ const overallTimeRange = useMemo(() => {
98
+ if (entries.length === 0) return null;
99
+ const now = performance.now();
100
+ return {
101
+ min: Math.min(...entries.map((e) => e.startTime)),
102
+ max: Math.max(...entries.map((e) => e.endTime ?? now)),
103
+ };
104
+ }, [entries]);
105
+
106
+ const filteredEntries = useMemo(() => {
107
+ if (!deferredSelection) return sortedEntries;
108
+ const [startTime, endTime] = deferredSelection;
109
+ const now = performance.now();
110
+ return sortedEntries.filter((entry) => {
111
+ const entryEnd = entry.endTime ?? now;
112
+ // Entry overlaps with selection if it starts before selection ends and ends after selection starts
113
+ return entry.startTime <= endTime && entryEnd >= startTime;
114
+ });
115
+ }, [sortedEntries, deferredSelection]);
116
+
117
+ const displayRange = deferredSelection
118
+ ? { min: deferredSelection[0], max: deferredSelection[1] }
119
+ : overallTimeRange;
120
+
121
+ // Calculate bar position for each entry
122
+ const getBarProps = (entry: SubscriptionEntry) => {
123
+ const range = (displayRange?.max ?? 1) - (displayRange?.min ?? 0) || 1;
124
+ const now = performance.now();
125
+
126
+ const clampedStart = Math.max(entry.startTime, displayRange?.min ?? 0);
127
+ const clampedEnd = Math.min(entry.endTime ?? now, displayRange?.max ?? now);
128
+
129
+ const left = Math.max(
130
+ 0,
131
+ ((clampedStart - (displayRange?.min ?? 0)) / range) * 100,
132
+ );
133
+ const width = Math.max(0, ((clampedEnd - clampedStart) / range) * 100);
134
+
135
+ const color =
136
+ entry.status === "pending"
137
+ ? "var(--j-warning-color)"
138
+ : entry.status === "error"
139
+ ? "var(--j-error-color)"
140
+ : "var(--j-success-color)";
141
+
142
+ return {
143
+ barLeft: `${left}%`,
144
+ barWidth: width === 0 ? "1px" : `${width}%`,
145
+ barColor: color,
146
+ };
147
+ };
148
+
149
+ const handleNavigateToCoValue = (id: string) => {
150
+ setPage(id as CoID<RawCoValue>);
151
+ onNavigate();
152
+ };
153
+
154
+ if (!SubscriptionScope.isProfilingEnabled) {
155
+ return (
156
+ <Container style={style}>
157
+ <EmptyState>Profiling is not enabled in production builds.</EmptyState>
158
+ </Container>
159
+ );
160
+ }
161
+
162
+ if (entries.length === 0) {
163
+ return (
164
+ <Container style={style}>
165
+ <EmptyState>
166
+ No subscriptions recorded yet. Interact with your app to see
167
+ subscription performance data.
168
+ </EmptyState>
169
+ </Container>
170
+ );
171
+ }
172
+
173
+ const selectedEntry = selectedRow
174
+ ? filteredEntries.find((e) => e.uuid === selectedRow)
175
+ : null;
176
+
177
+ return (
178
+ <Container style={style}>
179
+ {overallTimeRange && (
180
+ <Timeline
181
+ entries={sortedEntries}
182
+ timeRange={overallTimeRange}
183
+ selection={timeSelection}
184
+ onSelectionChange={setTimeSelection}
185
+ />
186
+ )}
187
+ <MainLayout>
188
+ <ListPanel>
189
+ <Grid>
190
+ <HeaderCell>Source</HeaderCell>
191
+ <HeaderCell>CoValue</HeaderCell>
192
+ <HeaderCell>Caller</HeaderCell>
193
+ <HeaderCell>Duration</HeaderCell>
194
+ {filteredEntries.map((entry) => (
195
+ <SubscriptionRow
196
+ key={entry.uuid}
197
+ entry={entry}
198
+ isSelected={selectedRow === entry.uuid}
199
+ onSelect={() => selectRow(entry.uuid)}
200
+ {...getBarProps(entry)}
201
+ />
202
+ ))}
203
+ </Grid>
204
+ </ListPanel>
205
+ {selectedEntry && (
206
+ <SubscriptionDetailPanel
207
+ entry={selectedEntry}
208
+ onNavigate={handleNavigateToCoValue}
209
+ onClose={() => setSelectedRow(null)}
210
+ />
211
+ )}
212
+ </MainLayout>
213
+ </Container>
214
+ );
215
+ }
@@ -0,0 +1,182 @@
1
+ import { styled } from "goober";
2
+ import type { SubscriptionEntry } from "./types.js";
3
+ import { formatTime, formatDuration, getCallerStack } from "./helpers.js";
4
+
5
+ // ============================================================================
6
+ // Styled Components
7
+ // ============================================================================
8
+
9
+ const DetailPanel = styled("div")`
10
+ width: 320px;
11
+ flex-shrink: 0;
12
+ padding: 0.75rem 1rem;
13
+ background-color: var(--j-foreground);
14
+ border: 1px solid var(--j-border-color);
15
+ border-radius: var(--j-radius-sm);
16
+ overflow-y: auto;
17
+ position: relative;
18
+ `;
19
+
20
+ const CloseButton = styled("button")`
21
+ position: absolute;
22
+ top: 0.5rem;
23
+ right: 0.5rem;
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ width: 18px;
28
+ height: 18px;
29
+ padding: 0;
30
+ background: none;
31
+ border: none;
32
+ border-radius: var(--j-radius-sm);
33
+ cursor: pointer;
34
+ color: var(--j-neutral-500);
35
+
36
+ &:hover {
37
+ background-color: var(--j-background);
38
+ color: var(--j-text-color);
39
+ }
40
+
41
+ &:focus-visible {
42
+ outline: 2px solid var(--j-primary-color);
43
+ outline-offset: -2px;
44
+ }
45
+ `;
46
+
47
+ const DetailsGrid = styled("div")`
48
+ display: grid;
49
+ grid-template-columns: auto 1fr;
50
+ gap: 0.5rem 1rem;
51
+ font-size: 0.625rem;
52
+ `;
53
+
54
+ const DetailLabel = styled("span")`
55
+ color: var(--j-neutral-500);
56
+ font-weight: 500;
57
+ `;
58
+
59
+ const DetailValue = styled("span")`
60
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
61
+ color: var(--j-text-color);
62
+ `;
63
+
64
+ const Pre = styled("pre")`
65
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
66
+ font-size: 0.625rem;
67
+ color: var(--j-text-color);
68
+ margin: 0;
69
+ white-space: pre-wrap;
70
+ word-break: break-all;
71
+ max-height: 200px;
72
+ overflow-y: auto;
73
+ background-color: var(--j-background);
74
+ padding: 0.5rem;
75
+ border-radius: var(--j-radius-sm);
76
+ `;
77
+
78
+ const StatusBadge = styled("span")`
79
+ display: inline-flex;
80
+ align-items: center;
81
+ gap: 0.25rem;
82
+ padding: 0.125rem 0.375rem;
83
+ border-radius: 0.25rem;
84
+ font-size: 0.625rem;
85
+
86
+ &[data-status="pending"] {
87
+ background-color: var(--j-warning-bg);
88
+ color: var(--j-warning-color);
89
+ }
90
+ &[data-status="loaded"] {
91
+ background-color: var(--j-success-bg);
92
+ color: var(--j-success-color);
93
+ }
94
+ &[data-status="error"] {
95
+ background-color: var(--j-error-bg);
96
+ color: var(--j-error-color);
97
+ }
98
+ `;
99
+
100
+ // ============================================================================
101
+ // Component
102
+ // ============================================================================
103
+
104
+ export interface SubscriptionDetailPanelProps {
105
+ entry: SubscriptionEntry;
106
+ onNavigate: (id: string) => void;
107
+ onClose: () => void;
108
+ }
109
+
110
+ export function SubscriptionDetailPanel({
111
+ entry,
112
+ onNavigate,
113
+ onClose,
114
+ }: SubscriptionDetailPanelProps) {
115
+ return (
116
+ <DetailPanel>
117
+ <CloseButton onClick={onClose} aria-label="Close detail panel">
118
+ <svg
119
+ width="10"
120
+ height="10"
121
+ viewBox="0 0 14 14"
122
+ fill="none"
123
+ xmlns="http://www.w3.org/2000/svg"
124
+ >
125
+ <path
126
+ d="M1 1L13 13M1 13L13 1"
127
+ stroke="currentColor"
128
+ strokeWidth="2"
129
+ strokeLinecap="round"
130
+ />
131
+ </svg>
132
+ </CloseButton>
133
+ <DetailsGrid>
134
+ <DetailLabel>Source</DetailLabel>
135
+ <DetailValue>
136
+ <StatusBadge data-status={entry.status}>{entry.source}</StatusBadge>
137
+ </DetailValue>
138
+
139
+ <DetailLabel>CoValue</DetailLabel>
140
+ <DetailValue>
141
+ <button
142
+ title="Click to navigate to CoValue"
143
+ onClick={() => onNavigate(entry.id)}
144
+ style={{
145
+ color: "var(--j-link-color)",
146
+ cursor: "pointer",
147
+ background: "none",
148
+ border: "none",
149
+ padding: 0,
150
+ font: "inherit",
151
+ }}
152
+ >
153
+ {entry.id}
154
+ </button>
155
+ </DetailValue>
156
+
157
+ <DetailLabel>Time</DetailLabel>
158
+ <DetailValue>
159
+ {formatTime(entry.startTime)} -{" "}
160
+ {entry.duration !== undefined
161
+ ? formatTime(entry.startTime + entry.duration)
162
+ : "Pending..."}
163
+ </DetailValue>
164
+
165
+ <DetailLabel>Duration</DetailLabel>
166
+ <DetailValue>
167
+ {entry.duration !== undefined
168
+ ? formatDuration(entry.duration)
169
+ : "Pending..."}
170
+ </DetailValue>
171
+
172
+ <DetailLabel>Resolve Query</DetailLabel>
173
+ <Pre>{JSON.stringify(JSON.parse(entry.resolve), null, 2)}</Pre>
174
+
175
+ <DetailLabel>Stack Trace</DetailLabel>
176
+ <Pre>
177
+ {getCallerStack(entry.callerStack) ?? "No stack trace available"}
178
+ </Pre>
179
+ </DetailsGrid>
180
+ </DetailPanel>
181
+ );
182
+ }
@@ -0,0 +1,242 @@
1
+ import { styled } from "goober";
2
+ import type { SubscriptionEntry } from "./types.js";
3
+ import { formatDuration, getCallerLocation } from "./helpers.js";
4
+
5
+ // ============================================================================
6
+ // Styled Components
7
+ // ============================================================================
8
+
9
+ const RowWrapper = styled("div")`
10
+ display: grid;
11
+ grid-template-columns: subgrid;
12
+ grid-column: 1 / -1;
13
+ position: relative;
14
+ cursor: pointer;
15
+
16
+ &:hover,
17
+ &:focus {
18
+ background-color: var(--j-foreground);
19
+ outline: none;
20
+ }
21
+
22
+ &:focus-visible {
23
+ outline: 2px solid var(--j-primary-color);
24
+ outline-offset: -2px;
25
+ }
26
+
27
+ &[data-expanded="true"] {
28
+ background-color: var(--j-foreground);
29
+ }
30
+ `;
31
+
32
+ const TimeBar = styled("div")`
33
+ position: absolute;
34
+ bottom: 0;
35
+ height: 4px;
36
+ transition: transform 0.15s ease;
37
+ z-index: 1;
38
+ container-type: inline-size;
39
+
40
+ .row-wrapper:hover &, [data-expanded="true"] & {
41
+ transform: scaleY(4);
42
+
43
+ .time-label {
44
+ opacity: 1;
45
+ }
46
+ }
47
+
48
+ &[data-status="pending"] {
49
+ animation: pulse 1.5s ease-in-out infinite;
50
+ }
51
+
52
+ @keyframes pulse {
53
+ 0%,
54
+ 100% {
55
+ opacity: 1;
56
+ }
57
+ 50% {
58
+ opacity: 0.5;
59
+ }
60
+ }
61
+ `;
62
+
63
+ const TimeLabel = styled("span")`
64
+ position: absolute;
65
+ top: 50%;
66
+ transform: translateY(-50%) scaleY(0.25);
67
+ font-size: 0.5rem;
68
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
69
+ color: white;
70
+ white-space: nowrap;
71
+ opacity: 0;
72
+ transition: opacity 0.15s ease;
73
+ pointer-events: none;
74
+ left: 4px;
75
+ --time-label-overflow-color: black;
76
+
77
+ @media (prefers-color-scheme: dark) {
78
+ --time-label-overflow-color: white;
79
+ }
80
+
81
+ @container (max-width: 50px) {
82
+ color: var(--time-label-overflow-color);
83
+ left: 100%;
84
+ margin-left: 4px;
85
+ }
86
+
87
+ [data-near-edge="true"] & {
88
+ @container (max-width: 50px) {
89
+ left: auto;
90
+ right: 100%;
91
+ margin-left: 0;
92
+ margin-right: 4px;
93
+ }
94
+ }
95
+ `;
96
+
97
+ const Cell = styled("div")`
98
+ padding: 0.5rem;
99
+ padding-bottom: 0.75rem;
100
+ font-size: 0.625rem;
101
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
102
+ border-bottom: 1px solid var(--j-border-color);
103
+ overflow: hidden;
104
+ text-overflow: ellipsis;
105
+ white-space: nowrap;
106
+
107
+ &[data-clickable="true"] {
108
+ cursor: pointer;
109
+ color: var(--j-link-color);
110
+ &:hover {
111
+ text-decoration: underline;
112
+ }
113
+ }
114
+ `;
115
+
116
+ const StatusBadge = styled("span")`
117
+ display: inline-flex;
118
+ align-items: center;
119
+ gap: 0.25rem;
120
+ padding: 0.125rem 0.375rem;
121
+ border-radius: 0.25rem;
122
+ font-size: 0.625rem;
123
+
124
+ &[data-status="pending"] {
125
+ background-color: var(--j-warning-bg);
126
+ color: var(--j-warning-color);
127
+ }
128
+ &[data-status="loaded"] {
129
+ background-color: var(--j-success-bg);
130
+ color: var(--j-success-color);
131
+ }
132
+ &[data-status="error"] {
133
+ background-color: var(--j-error-bg);
134
+ color: var(--j-error-color);
135
+ }
136
+ `;
137
+
138
+ const PendingDot = styled("span")`
139
+ display: inline-block;
140
+ width: 8px;
141
+ height: 8px;
142
+ border-radius: 50%;
143
+ background-color: var(--j-warning-color);
144
+ animation: pendingPulse 1.5s ease-in-out infinite;
145
+
146
+ @keyframes pendingPulse {
147
+ 0%,
148
+ 100% {
149
+ opacity: 1;
150
+ }
151
+ 50% {
152
+ opacity: 0.4;
153
+ }
154
+ }
155
+ `;
156
+
157
+ // ============================================================================
158
+ // Component
159
+ // ============================================================================
160
+
161
+ export interface SubscriptionRowProps {
162
+ entry: SubscriptionEntry;
163
+ isSelected: boolean;
164
+ onSelect: () => void;
165
+ barLeft: string;
166
+ barWidth: string;
167
+ barColor: string;
168
+ }
169
+
170
+ export function SubscriptionRow({
171
+ entry,
172
+ isSelected,
173
+ onSelect,
174
+ barLeft,
175
+ barWidth,
176
+ barColor,
177
+ }: SubscriptionRowProps) {
178
+ const handleKeyDown = (e: React.KeyboardEvent) => {
179
+ if (e.key === "Enter" || e.key === " ") {
180
+ e.preventDefault();
181
+ onSelect();
182
+ }
183
+ };
184
+
185
+ return (
186
+ <RowWrapper
187
+ className="row-wrapper"
188
+ data-expanded={isSelected}
189
+ onClick={onSelect}
190
+ onKeyDown={handleKeyDown}
191
+ tabIndex={0}
192
+ role="button"
193
+ aria-label={`View details for ${entry.source} ${entry.id}`}
194
+ >
195
+ <Cell>
196
+ <StatusBadge data-status={entry.status}>{entry.source}</StatusBadge>
197
+ </Cell>
198
+ <Cell>
199
+ <div
200
+ style={{
201
+ display: "flex",
202
+ flexDirection: "column",
203
+ gap: "0.125rem",
204
+ }}
205
+ >
206
+ <span>{entry.id}</span>
207
+ <span style={{ color: "var(--j-neutral-500)" }}>{entry.resolve}</span>
208
+ </div>
209
+ </Cell>
210
+ <Cell>{getCallerLocation(entry.callerStack) ?? "-"}</Cell>
211
+ <Cell>
212
+ {entry.duration !== undefined ? (
213
+ entry.duration === 0 ? (
214
+ "⚡ cached"
215
+ ) : (
216
+ formatDuration(entry.duration)
217
+ )
218
+ ) : (
219
+ <PendingDot />
220
+ )}
221
+ </Cell>
222
+ <TimeBar
223
+ className="time-bar"
224
+ data-status={entry.status}
225
+ data-near-edge={parseFloat(barLeft) + parseFloat(barWidth) > 85}
226
+ style={{
227
+ left: barLeft,
228
+ width: barWidth,
229
+ backgroundColor: barColor,
230
+ }}
231
+ >
232
+ <TimeLabel className="time-label">
233
+ {entry.duration === 0
234
+ ? "⚡ cached"
235
+ : entry.duration
236
+ ? formatDuration(entry.duration)
237
+ : "-"}
238
+ </TimeLabel>
239
+ </TimeBar>
240
+ </RowWrapper>
241
+ );
242
+ }