react-native-debug-toolkit 0.6.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +149 -211
- package/README.zh-CN.md +150 -171
- package/lib/commonjs/components/ClipboardTab.js +91 -0
- package/lib/commonjs/components/ClipboardTab.js.map +1 -0
- package/lib/commonjs/components/ConsoleLogTab.js +162 -0
- package/lib/commonjs/components/ConsoleLogTab.js.map +1 -0
- package/lib/commonjs/components/DebugPanel.js +230 -0
- package/lib/commonjs/components/DebugPanel.js.map +1 -0
- package/lib/commonjs/components/DebugView.js +66 -0
- package/lib/commonjs/components/DebugView.js.map +1 -0
- package/lib/commonjs/components/EnvironmentTab.js +287 -0
- package/lib/commonjs/components/EnvironmentTab.js.map +1 -0
- package/lib/commonjs/components/FeatureTabBar.js +182 -0
- package/lib/commonjs/components/FeatureTabBar.js.map +1 -0
- package/lib/commonjs/components/FloatIcon.js +187 -0
- package/lib/commonjs/components/FloatIcon.js.map +1 -0
- package/lib/commonjs/components/FloatPanelView.js +214 -0
- package/lib/commonjs/components/FloatPanelView.js.map +1 -0
- package/lib/commonjs/components/NavigationLogTab.js +131 -0
- package/lib/commonjs/components/NavigationLogTab.js.map +1 -0
- package/lib/commonjs/components/NetworkLogTab.js +404 -0
- package/lib/commonjs/components/NetworkLogTab.js.map +1 -0
- package/lib/commonjs/components/ThirdPartyLibsTab.js +97 -0
- package/lib/commonjs/components/ThirdPartyLibsTab.js.map +1 -0
- package/lib/commonjs/components/TrackLogTab.js +230 -0
- package/lib/commonjs/components/TrackLogTab.js.map +1 -0
- package/lib/commonjs/components/ZustandLogTab.js +311 -0
- package/lib/commonjs/components/ZustandLogTab.js.map +1 -0
- package/lib/commonjs/components/shared/CollapsibleSection.js +84 -0
- package/lib/commonjs/components/shared/CollapsibleSection.js.map +1 -0
- package/lib/commonjs/components/shared/CopyButton.js +64 -0
- package/lib/commonjs/components/shared/CopyButton.js.map +1 -0
- package/lib/commonjs/components/shared/JsonView.js +157 -0
- package/lib/commonjs/components/shared/JsonView.js.map +1 -0
- package/lib/commonjs/components/shared/LogListScreen.js +174 -0
- package/lib/commonjs/components/shared/LogListScreen.js.map +1 -0
- package/lib/commonjs/core/DebugToolkit.js +122 -0
- package/lib/commonjs/core/DebugToolkit.js.map +1 -0
- package/lib/commonjs/core/DebugToolkitProvider.js +66 -0
- package/lib/commonjs/core/DebugToolkitProvider.js.map +1 -0
- package/lib/commonjs/features/ClipboardFeature.js +21 -0
- package/lib/commonjs/features/ClipboardFeature.js.map +1 -0
- package/lib/commonjs/features/ConsoleLogFeature.js +115 -0
- package/lib/commonjs/features/ConsoleLogFeature.js.map +1 -0
- package/lib/commonjs/features/EnvironmentFeature.js +160 -0
- package/lib/commonjs/features/EnvironmentFeature.js.map +1 -0
- package/lib/commonjs/features/NavigationLogFeature.js +39 -0
- package/lib/commonjs/features/NavigationLogFeature.js.map +1 -0
- package/lib/commonjs/features/NetworkFeature.js +107 -0
- package/lib/commonjs/features/NetworkFeature.js.map +1 -0
- package/lib/commonjs/features/ThirdPartyLibsFeature.js +51 -0
- package/lib/commonjs/features/ThirdPartyLibsFeature.js.map +1 -0
- package/lib/commonjs/features/TrackFeature.js +34 -0
- package/lib/commonjs/features/TrackFeature.js.map +1 -0
- package/lib/commonjs/features/ZustandLogFeature.js +59 -0
- package/lib/commonjs/features/ZustandLogFeature.js.map +1 -0
- package/lib/commonjs/hooks/useNavigationLogger.js +78 -0
- package/lib/commonjs/hooks/useNavigationLogger.js.map +1 -0
- package/lib/commonjs/hooks/useSlideDetailAnimation.js +53 -0
- package/lib/commonjs/hooks/useSlideDetailAnimation.js.map +1 -0
- package/lib/commonjs/index.js +152 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/initialize.js +84 -0
- package/lib/commonjs/initialize.js.map +1 -0
- package/lib/commonjs/interceptors/networkInterceptor.js +466 -0
- package/lib/commonjs/interceptors/networkInterceptor.js.map +1 -0
- package/lib/commonjs/native/NativeDebugLibs.js +58 -0
- package/lib/commonjs/native/NativeDebugLibs.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/index.js +6 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/utils/colors.js +48 -0
- package/lib/commonjs/utils/colors.js.map +1 -0
- package/lib/commonjs/utils/copyToComputer.js +97 -0
- package/lib/commonjs/utils/copyToComputer.js.map +1 -0
- package/lib/commonjs/utils/createChannelFeature.js +48 -0
- package/lib/commonjs/utils/createChannelFeature.js.map +1 -0
- package/lib/commonjs/utils/createEventChannel.js +21 -0
- package/lib/commonjs/utils/createEventChannel.js.map +1 -0
- package/lib/commonjs/utils/createObservableStore.js +38 -0
- package/lib/commonjs/utils/createObservableStore.js.map +1 -0
- package/lib/commonjs/utils/layout.js +8 -0
- package/lib/commonjs/utils/layout.js.map +1 -0
- package/lib/commonjs/utils/safeStringify.js +27 -0
- package/lib/commonjs/utils/safeStringify.js.map +1 -0
- package/lib/commonjs/utils/urlRewriterRegistry.js +14 -0
- package/lib/commonjs/utils/urlRewriterRegistry.js.map +1 -0
- package/lib/module/components/ClipboardTab.js +86 -0
- package/lib/module/components/ClipboardTab.js.map +1 -0
- package/lib/module/components/ConsoleLogTab.js +157 -0
- package/lib/module/components/ConsoleLogTab.js.map +1 -0
- package/lib/module/components/DebugPanel.js +225 -0
- package/lib/module/components/DebugPanel.js.map +1 -0
- package/lib/module/components/DebugView.js +61 -0
- package/lib/module/components/DebugView.js.map +1 -0
- package/lib/module/components/EnvironmentTab.js +282 -0
- package/lib/module/components/EnvironmentTab.js.map +1 -0
- package/lib/module/components/FeatureTabBar.js +177 -0
- package/lib/module/components/FeatureTabBar.js.map +1 -0
- package/lib/module/components/FloatIcon.js +182 -0
- package/lib/module/components/FloatIcon.js.map +1 -0
- package/lib/module/components/FloatPanelView.js +209 -0
- package/lib/module/components/FloatPanelView.js.map +1 -0
- package/lib/module/components/NavigationLogTab.js +126 -0
- package/lib/module/components/NavigationLogTab.js.map +1 -0
- package/lib/module/components/NetworkLogTab.js +399 -0
- package/lib/module/components/NetworkLogTab.js.map +1 -0
- package/lib/module/components/ThirdPartyLibsTab.js +91 -0
- package/lib/module/components/ThirdPartyLibsTab.js.map +1 -0
- package/lib/module/components/TrackLogTab.js +225 -0
- package/lib/module/components/TrackLogTab.js.map +1 -0
- package/lib/module/components/ZustandLogTab.js +306 -0
- package/lib/module/components/ZustandLogTab.js.map +1 -0
- package/lib/module/components/shared/CollapsibleSection.js +78 -0
- package/lib/module/components/shared/CollapsibleSection.js.map +1 -0
- package/lib/module/components/shared/CopyButton.js +58 -0
- package/lib/module/components/shared/CopyButton.js.map +1 -0
- package/lib/module/components/shared/JsonView.js +152 -0
- package/lib/module/components/shared/JsonView.js.map +1 -0
- package/lib/module/components/shared/LogListScreen.js +169 -0
- package/lib/module/components/shared/LogListScreen.js.map +1 -0
- package/lib/module/core/DebugToolkit.js +118 -0
- package/lib/module/core/DebugToolkit.js.map +1 -0
- package/lib/module/core/DebugToolkitProvider.js +60 -0
- package/lib/module/core/DebugToolkitProvider.js.map +1 -0
- package/lib/module/features/ClipboardFeature.js +16 -0
- package/lib/module/features/ClipboardFeature.js.map +1 -0
- package/lib/module/features/ConsoleLogFeature.js +109 -0
- package/lib/module/features/ConsoleLogFeature.js.map +1 -0
- package/lib/module/features/EnvironmentFeature.js +156 -0
- package/lib/module/features/EnvironmentFeature.js.map +1 -0
- package/lib/module/features/NavigationLogFeature.js +32 -0
- package/lib/module/features/NavigationLogFeature.js.map +1 -0
- package/lib/module/features/NetworkFeature.js +101 -0
- package/lib/module/features/NetworkFeature.js.map +1 -0
- package/lib/module/features/ThirdPartyLibsFeature.js +46 -0
- package/lib/module/features/ThirdPartyLibsFeature.js.map +1 -0
- package/lib/module/features/TrackFeature.js +27 -0
- package/lib/module/features/TrackFeature.js.map +1 -0
- package/lib/module/features/ZustandLogFeature.js +53 -0
- package/lib/module/features/ZustandLogFeature.js.map +1 -0
- package/lib/module/hooks/useNavigationLogger.js +74 -0
- package/lib/module/hooks/useNavigationLogger.js.map +1 -0
- package/lib/module/hooks/useSlideDetailAnimation.js +50 -0
- package/lib/module/hooks/useSlideDetailAnimation.js.map +1 -0
- package/lib/module/index.js +28 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initialize.js +80 -0
- package/lib/module/initialize.js.map +1 -0
- package/lib/module/interceptors/networkInterceptor.js +460 -0
- package/lib/module/interceptors/networkInterceptor.js.map +1 -0
- package/lib/module/native/NativeDebugLibs.js +54 -0
- package/lib/module/native/NativeDebugLibs.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/colors.js +43 -0
- package/lib/module/utils/colors.js.map +1 -0
- package/lib/module/utils/copyToComputer.js +91 -0
- package/lib/module/utils/copyToComputer.js.map +1 -0
- package/lib/module/utils/createChannelFeature.js +44 -0
- package/lib/module/utils/createChannelFeature.js.map +1 -0
- package/lib/module/utils/createEventChannel.js +17 -0
- package/lib/module/utils/createEventChannel.js.map +1 -0
- package/lib/module/utils/createObservableStore.js +34 -0
- package/lib/module/utils/createObservableStore.js.map +1 -0
- package/lib/module/utils/layout.js +4 -0
- package/lib/module/utils/layout.js.map +1 -0
- package/lib/module/utils/safeStringify.js +23 -0
- package/lib/module/utils/safeStringify.js.map +1 -0
- package/lib/module/utils/urlRewriterRegistry.js +10 -0
- package/lib/module/utils/urlRewriterRegistry.js.map +1 -0
- package/lib/typescript/src/components/ClipboardTab.d.ts +4 -0
- package/lib/typescript/src/components/ClipboardTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ConsoleLogTab.d.ts +4 -0
- package/lib/typescript/src/components/ConsoleLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/DebugPanel.d.ts +9 -0
- package/lib/typescript/src/components/DebugPanel.d.ts.map +1 -0
- package/lib/typescript/src/components/DebugView.d.ts +19 -0
- package/lib/typescript/src/components/DebugView.d.ts.map +1 -0
- package/lib/typescript/src/components/EnvironmentTab.d.ts +4 -0
- package/lib/typescript/src/components/EnvironmentTab.d.ts.map +1 -0
- package/lib/typescript/src/components/FeatureTabBar.d.ts +13 -0
- package/lib/typescript/src/components/FeatureTabBar.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatIcon.d.ts +12 -0
- package/lib/typescript/src/components/FloatIcon.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatPanelView.d.ts +9 -0
- package/lib/typescript/src/components/FloatPanelView.d.ts.map +1 -0
- package/lib/typescript/src/components/NavigationLogTab.d.ts +4 -0
- package/lib/typescript/src/components/NavigationLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/NetworkLogTab.d.ts +4 -0
- package/lib/typescript/src/components/NetworkLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts +4 -0
- package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts.map +1 -0
- package/lib/typescript/src/components/TrackLogTab.d.ts +4 -0
- package/lib/typescript/src/components/TrackLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ZustandLogTab.d.ts +4 -0
- package/lib/typescript/src/components/ZustandLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/CollapsibleSection.d.ts +9 -0
- package/lib/typescript/src/components/shared/CollapsibleSection.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/CopyButton.d.ts +12 -0
- package/lib/typescript/src/components/shared/CopyButton.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/JsonView.d.ts +6 -0
- package/lib/typescript/src/components/shared/JsonView.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/LogListScreen.d.ts +21 -0
- package/lib/typescript/src/components/shared/LogListScreen.d.ts.map +1 -0
- package/lib/typescript/src/core/DebugToolkit.d.ts +20 -0
- package/lib/typescript/src/core/DebugToolkit.d.ts.map +1 -0
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts +15 -0
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts.map +1 -0
- package/lib/typescript/src/features/ClipboardFeature.d.ts +7 -0
- package/lib/typescript/src/features/ClipboardFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts +9 -0
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/EnvironmentFeature.d.ts +8 -0
- package/lib/typescript/src/features/EnvironmentFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/NavigationLogFeature.d.ts +10 -0
- package/lib/typescript/src/features/NavigationLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/NetworkFeature.d.ts +15 -0
- package/lib/typescript/src/features/NetworkFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts +3 -0
- package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/TrackFeature.d.ts +14 -0
- package/lib/typescript/src/features/TrackFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ZustandLogFeature.d.ts +31 -0
- package/lib/typescript/src/features/ZustandLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts +13 -0
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts +11 -0
- package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +26 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/initialize.d.ts +32 -0
- package/lib/typescript/src/initialize.d.ts.map +1 -0
- package/lib/typescript/src/interceptors/networkInterceptor.d.ts +18 -0
- package/lib/typescript/src/interceptors/networkInterceptor.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeDebugLibs.d.ts +11 -0
- package/lib/typescript/src/native/NativeDebugLibs.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +109 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/colors.d.ts +21 -0
- package/lib/typescript/src/utils/colors.d.ts.map +1 -0
- package/lib/typescript/src/utils/copyToComputer.d.ts +30 -0
- package/lib/typescript/src/utils/copyToComputer.d.ts.map +1 -0
- package/lib/typescript/src/utils/createChannelFeature.d.ts +18 -0
- package/lib/typescript/src/utils/createChannelFeature.d.ts.map +1 -0
- package/lib/typescript/src/utils/createEventChannel.d.ts +7 -0
- package/lib/typescript/src/utils/createEventChannel.d.ts.map +1 -0
- package/lib/typescript/src/utils/createObservableStore.d.ts +9 -0
- package/lib/typescript/src/utils/createObservableStore.d.ts.map +1 -0
- package/lib/typescript/src/utils/layout.d.ts +2 -0
- package/lib/typescript/src/utils/layout.d.ts.map +1 -0
- package/lib/typescript/src/utils/safeStringify.d.ts +6 -0
- package/lib/typescript/src/utils/safeStringify.d.ts.map +1 -0
- package/lib/typescript/src/utils/urlRewriterRegistry.d.ts +7 -0
- package/lib/typescript/src/utils/urlRewriterRegistry.d.ts.map +1 -0
- package/package.json +67 -24
- package/src/components/ClipboardTab.tsx +81 -0
- package/src/components/ConsoleLogTab.tsx +95 -0
- package/src/components/DebugPanel.tsx +215 -0
- package/src/components/DebugView.tsx +80 -0
- package/src/components/EnvironmentTab.tsx +276 -0
- package/src/components/FeatureTabBar.tsx +204 -0
- package/src/components/FloatIcon.tsx +171 -0
- package/src/components/FloatPanelView.tsx +202 -0
- package/src/components/NavigationLogTab.tsx +66 -0
- package/src/components/NetworkLogTab.tsx +270 -0
- package/src/components/ThirdPartyLibsTab.tsx +63 -0
- package/src/components/TrackLogTab.tsx +110 -0
- package/src/components/ZustandLogTab.tsx +203 -0
- package/src/components/shared/CollapsibleSection.tsx +78 -0
- package/src/components/shared/CopyButton.tsx +68 -0
- package/src/components/shared/JsonView.tsx +125 -0
- package/src/components/shared/LogListScreen.tsx +164 -0
- package/src/core/DebugToolkit.tsx +150 -0
- package/src/core/DebugToolkitProvider.tsx +83 -0
- package/src/features/ClipboardFeature.ts +15 -0
- package/src/features/ConsoleLogFeature.ts +116 -0
- package/src/features/EnvironmentFeature.ts +186 -0
- package/src/features/NavigationLogFeature.ts +44 -0
- package/src/features/NetworkFeature.ts +126 -0
- package/src/features/ThirdPartyLibsFeature.ts +42 -0
- package/src/features/TrackFeature.ts +34 -0
- package/src/features/ZustandLogFeature.ts +101 -0
- package/src/hooks/useNavigationLogger.ts +102 -0
- package/src/hooks/useSlideDetailAnimation.ts +45 -0
- package/src/index.ts +48 -0
- package/src/initialize.ts +122 -0
- package/src/interceptors/networkInterceptor.ts +646 -0
- package/src/native/NativeDebugLibs.ts +74 -0
- package/src/types/index.ts +127 -0
- package/src/utils/colors.ts +38 -0
- package/src/utils/copyToComputer.ts +104 -0
- package/src/utils/createChannelFeature.ts +55 -0
- package/src/utils/createEventChannel.ts +22 -0
- package/src/utils/createObservableStore.ts +42 -0
- package/src/utils/layout.ts +1 -0
- package/src/utils/safeStringify.ts +25 -0
- package/src/utils/urlRewriterRegistry.ts +10 -0
- package/.cursor/rules/react-native.mdc +0 -41
- package/index.js +0 -41
- package/ios/BuildTypeModule.h +0 -9
- package/ios/BuildTypeModule.m +0 -42
- package/ios/RNDebugLibs.h +0 -10
- package/ios/RNDebugLibs.m +0 -79
- package/lib/DebugToolKit.js +0 -126
- package/lib/EnvironmentManager.ts +0 -80
- package/lib/NativeDebugLibs.js +0 -67
- package/lib/features/ConsoleLogFeature.js +0 -70
- package/lib/features/NavigationLogFeature.js +0 -45
- package/lib/features/NetworkFeature.js +0 -389
- package/lib/features/PerformanceFeature.js +0 -390
- package/lib/features/ThirdPartyLibsFeature.js +0 -63
- package/lib/features/TrackFeature.js +0 -94
- package/lib/features/ZustandLogFeature.js +0 -44
- package/lib/hooks/useNavigationLogger.js +0 -92
- package/lib/index.js +0 -114
- package/lib/navigation/NavigationLogger.js +0 -1
- package/lib/types/TrackTypes.ts +0 -92
- package/lib/utils/DebugConst.js +0 -67
- package/lib/utils/StorageUtils.js +0 -80
- package/lib/views/ConsoleLogDetails.js +0 -314
- package/lib/views/FloatPanelView.js +0 -697
- package/lib/views/HttpLogDetails.js +0 -648
- package/lib/views/NavigationLogDetails.js +0 -302
- package/lib/views/RestartModal.js +0 -75
- package/lib/views/SubViewConsoleLogs.js +0 -209
- package/lib/views/SubViewEnvironment.js +0 -73
- package/lib/views/SubViewHTTPLogs.js +0 -235
- package/lib/views/SubViewNavigationLogs.js +0 -199
- package/lib/views/SubViewPerformance.js +0 -515
- package/lib/views/SubViewThirdPartyLibs.js +0 -239
- package/lib/views/SubViewTrackLogs.js +0 -318
- package/lib/views/SubViewZustandLogs.js +0 -279
- package/lib/views/TabView.js +0 -66
- package/lib/views/TrackLogDetails.js +0 -481
- package/lib/views/ZustandLogDetails.js +0 -355
- package/react-native-debug-toolkit.podspec +0 -25
- package/react-native.config.js +0 -18
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text, StyleSheet, ScrollView } from 'react-native';
|
|
3
|
+
import { Colors } from '../utils/colors';
|
|
4
|
+
import { safeStringify } from '../utils/safeStringify';
|
|
5
|
+
import { CollapsibleSection } from './shared/CollapsibleSection';
|
|
6
|
+
import { JsonView } from './shared/JsonView';
|
|
7
|
+
import { CopyButton } from './shared/CopyButton';
|
|
8
|
+
import { LogListScreen } from './shared/LogListScreen';
|
|
9
|
+
import type { DebugFeatureRenderProps, TrackLogEntry } from '../types';
|
|
10
|
+
|
|
11
|
+
export const TrackLogTab: React.FC<DebugFeatureRenderProps<TrackLogEntry>> = React.memo(({ data }) => (
|
|
12
|
+
<LogListScreen
|
|
13
|
+
data={data}
|
|
14
|
+
emptyText="No track events"
|
|
15
|
+
renderRow={(item) => (
|
|
16
|
+
<View style={s.cardRow}>
|
|
17
|
+
<View style={s.eventIcon}><Text style={s.eventIconText}>●</Text></View>
|
|
18
|
+
<View style={s.cardContent}>
|
|
19
|
+
<View style={s.cardHeader}>
|
|
20
|
+
<Text style={s.eventName}>{item.eventName}</Text>
|
|
21
|
+
<Text style={s.time}>{new Date(item.timestamp).toLocaleTimeString()}</Text>
|
|
22
|
+
</View>
|
|
23
|
+
<View style={s.previewRow}>
|
|
24
|
+
{Object.entries(item)
|
|
25
|
+
.filter(([k]) => k !== 'id' && k !== 'eventName' && k !== 'timestamp')
|
|
26
|
+
.slice(0, 2)
|
|
27
|
+
.map(([key, value]) => (
|
|
28
|
+
<View key={key} style={s.previewChip}>
|
|
29
|
+
<Text style={s.previewText} numberOfLines={1}>
|
|
30
|
+
<Text style={s.previewKey}>{key}</Text> {String(value ?? '').slice(0, 25)}
|
|
31
|
+
</Text>
|
|
32
|
+
</View>
|
|
33
|
+
))}
|
|
34
|
+
</View>
|
|
35
|
+
</View>
|
|
36
|
+
</View>
|
|
37
|
+
)}
|
|
38
|
+
renderDetailHeader={(item) => (
|
|
39
|
+
<View style={s.eventBadge}><Text style={s.eventBadgeText}>{item.eventName}</Text></View>
|
|
40
|
+
)}
|
|
41
|
+
renderDetailBody={(item) => {
|
|
42
|
+
const extraProps = Object.entries(item).filter(
|
|
43
|
+
([k, v]) => k !== 'id' && k !== 'eventName' && k !== 'timestamp' && v !== undefined && v !== null,
|
|
44
|
+
);
|
|
45
|
+
return (
|
|
46
|
+
<ScrollView style={s.detailBody} contentContainerStyle={s.detailBodyContent}>
|
|
47
|
+
<CollapsibleSection title="Properties" initiallyExpanded>
|
|
48
|
+
<View style={s.sectionWithCopy}>
|
|
49
|
+
<CopyButton text={safeStringify(Object.fromEntries(extraProps), 2)} label="Track Properties" />
|
|
50
|
+
<View style={s.propsGrid}>
|
|
51
|
+
{extraProps.map(([key, value]) => (
|
|
52
|
+
<View key={key} style={s.propRow}>
|
|
53
|
+
<Text style={s.propKey}>{key}</Text>
|
|
54
|
+
<Text style={s.propValue} selectable>
|
|
55
|
+
{typeof value === 'object' ? safeStringify(value) : String(value ?? '')}
|
|
56
|
+
</Text>
|
|
57
|
+
</View>
|
|
58
|
+
))}
|
|
59
|
+
</View>
|
|
60
|
+
</View>
|
|
61
|
+
</CollapsibleSection>
|
|
62
|
+
<CollapsibleSection title="Full Event Data">
|
|
63
|
+
<View style={s.sectionWithCopy}>
|
|
64
|
+
<CopyButton text={safeStringify(item, 2)} label="Track Event" />
|
|
65
|
+
<JsonView data={item} maxHeight={300} />
|
|
66
|
+
</View>
|
|
67
|
+
</CollapsibleSection>
|
|
68
|
+
<View style={s.timingCard}>
|
|
69
|
+
<Text style={s.timingLabel}>Time</Text>
|
|
70
|
+
<Text style={s.timingValue}>{new Date(item.timestamp).toLocaleString()}</Text>
|
|
71
|
+
</View>
|
|
72
|
+
</ScrollView>
|
|
73
|
+
);
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
));
|
|
77
|
+
|
|
78
|
+
const s = StyleSheet.create({
|
|
79
|
+
cardRow: { flexDirection: 'row', padding: 14, alignItems: 'flex-start' },
|
|
80
|
+
eventIcon: {
|
|
81
|
+
width: 28, height: 28, borderRadius: 8,
|
|
82
|
+
backgroundColor: 'rgba(175,82,222,0.1)',
|
|
83
|
+
alignItems: 'center', justifyContent: 'center',
|
|
84
|
+
marginRight: 12, marginTop: 1,
|
|
85
|
+
},
|
|
86
|
+
eventIconText: { color: Colors.purple, fontSize: 10 },
|
|
87
|
+
cardContent: { flex: 1 },
|
|
88
|
+
cardHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 },
|
|
89
|
+
eventName: { fontSize: 15, fontWeight: '600', color: Colors.text },
|
|
90
|
+
time: { fontSize: 12, color: Colors.textSecondary },
|
|
91
|
+
previewRow: { flexDirection: 'row', flexWrap: 'wrap', gap: 4 },
|
|
92
|
+
previewChip: { backgroundColor: Colors.background, borderRadius: 6, paddingHorizontal: 8, paddingVertical: 3 },
|
|
93
|
+
previewText: { fontSize: 12, color: Colors.textSecondary, lineHeight: 16 },
|
|
94
|
+
previewKey: { fontWeight: '600', color: Colors.text },
|
|
95
|
+
eventBadge: { backgroundColor: Colors.purple, paddingHorizontal: 12, paddingVertical: 5, borderRadius: 8 },
|
|
96
|
+
eventBadgeText: { color: '#FFF', fontSize: 14, fontWeight: '700' },
|
|
97
|
+
detailBody: { flex: 1 },
|
|
98
|
+
detailBodyContent: { padding: 12, paddingBottom: 40 },
|
|
99
|
+
sectionWithCopy: { gap: 8 },
|
|
100
|
+
propsGrid: { gap: 12 },
|
|
101
|
+
propRow: {},
|
|
102
|
+
propKey: { fontSize: 13, fontWeight: '600', color: Colors.textSecondary, marginBottom: 3 },
|
|
103
|
+
propValue: { fontSize: 14, color: Colors.text, lineHeight: 20 },
|
|
104
|
+
timingCard: {
|
|
105
|
+
backgroundColor: Colors.surface, borderRadius: 12, padding: 14,
|
|
106
|
+
flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginTop: 4,
|
|
107
|
+
},
|
|
108
|
+
timingLabel: { fontSize: 13, color: Colors.textSecondary, fontWeight: '500' },
|
|
109
|
+
timingValue: { fontSize: 13, color: Colors.text },
|
|
110
|
+
});
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text, StyleSheet, ScrollView } from 'react-native';
|
|
3
|
+
import { Colors } from '../utils/colors';
|
|
4
|
+
import { safeStringify } from '../utils/safeStringify';
|
|
5
|
+
import { CollapsibleSection } from './shared/CollapsibleSection';
|
|
6
|
+
import { JsonView } from './shared/JsonView';
|
|
7
|
+
import { CopyButton } from './shared/CopyButton';
|
|
8
|
+
import { LogListScreen } from './shared/LogListScreen';
|
|
9
|
+
import type { DebugFeatureRenderProps, ZustandLogEntry } from '../types';
|
|
10
|
+
|
|
11
|
+
const getActionColor = (action: string): string => {
|
|
12
|
+
if (action.includes('add') || action.includes('create')) return '#34C759';
|
|
13
|
+
if (action.includes('remove') || action.includes('delete')) return '#FF3B30';
|
|
14
|
+
if (action.includes('update') || action.includes('set')) return '#007AFF';
|
|
15
|
+
return '#AF52DE';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getActionBgColor = (action: string): string => {
|
|
19
|
+
if (action.includes('add') || action.includes('create')) return 'rgba(52,199,89,0.1)';
|
|
20
|
+
if (action.includes('remove') || action.includes('delete')) return 'rgba(255,59,48,0.1)';
|
|
21
|
+
if (action.includes('update') || action.includes('set')) return 'rgba(0,122,255,0.1)';
|
|
22
|
+
return 'rgba(175,82,222,0.1)';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function findChanges(prev: unknown, next: unknown): string[] {
|
|
26
|
+
if (typeof prev !== 'object' || typeof next !== 'object' || !prev || !next) return [];
|
|
27
|
+
const allKeys = new Set([...Object.keys(prev as object), ...Object.keys(next as object)]);
|
|
28
|
+
const changed: string[] = [];
|
|
29
|
+
allKeys.forEach((key) => {
|
|
30
|
+
const pv = (prev as Record<string, unknown>)[key];
|
|
31
|
+
const nv = (next as Record<string, unknown>)[key];
|
|
32
|
+
if (safeStringify(pv) !== safeStringify(nv)) changed.push(key);
|
|
33
|
+
});
|
|
34
|
+
return changed;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const ZustandLogTab: React.FC<DebugFeatureRenderProps<ZustandLogEntry>> = React.memo(({
|
|
38
|
+
data,
|
|
39
|
+
}) => (
|
|
40
|
+
<LogListScreen
|
|
41
|
+
data={data}
|
|
42
|
+
emptyText="No Zustand state changes"
|
|
43
|
+
renderRow={(item) => (
|
|
44
|
+
<View style={s.cardRow}>
|
|
45
|
+
<View style={[s.actionIcon, { backgroundColor: getActionBgColor(item.action) }]}>
|
|
46
|
+
<View style={[s.actionDot, { backgroundColor: getActionColor(item.action) }]} />
|
|
47
|
+
</View>
|
|
48
|
+
<View style={s.cardContent}>
|
|
49
|
+
<View style={s.cardMeta}>
|
|
50
|
+
<Text style={s.action}>{item.action}</Text>
|
|
51
|
+
{item.storeName && (
|
|
52
|
+
<View style={s.storeBadge}>
|
|
53
|
+
<Text style={s.storeBadgeText}>{item.storeName}</Text>
|
|
54
|
+
</View>
|
|
55
|
+
)}
|
|
56
|
+
</View>
|
|
57
|
+
<Text style={s.time}>{new Date(item.timestamp).toLocaleTimeString()}</Text>
|
|
58
|
+
</View>
|
|
59
|
+
{item.actionCompleteTime != null && (
|
|
60
|
+
<View style={s.durationBadge}>
|
|
61
|
+
<Text style={s.durationText}>{item.actionCompleteTime}ms</Text>
|
|
62
|
+
</View>
|
|
63
|
+
)}
|
|
64
|
+
</View>
|
|
65
|
+
)}
|
|
66
|
+
renderDetailHeader={(item) => (
|
|
67
|
+
<View style={s.detailHeaderCenter}>
|
|
68
|
+
<Text style={[s.detailAction, { color: getActionColor(item.action) }]}>
|
|
69
|
+
{item.action}
|
|
70
|
+
</Text>
|
|
71
|
+
{item.storeName && (
|
|
72
|
+
<View style={s.storeBadge}>
|
|
73
|
+
<Text style={s.storeBadgeText}>{item.storeName}</Text>
|
|
74
|
+
</View>
|
|
75
|
+
)}
|
|
76
|
+
</View>
|
|
77
|
+
)}
|
|
78
|
+
renderDetailBody={(item) => {
|
|
79
|
+
const changes = findChanges(item.prevState, item.nextState);
|
|
80
|
+
return (
|
|
81
|
+
<ScrollView style={s.detailBody} contentContainerStyle={s.detailBodyContent}>
|
|
82
|
+
<View style={s.metaCard}>
|
|
83
|
+
<View style={s.metaItem}>
|
|
84
|
+
<Text style={s.metaLabel}>Time</Text>
|
|
85
|
+
<Text style={s.metaValue}>{new Date(item.timestamp).toLocaleString()}</Text>
|
|
86
|
+
</View>
|
|
87
|
+
{item.actionCompleteTime != null && <View style={s.metaDivider} />}
|
|
88
|
+
{item.actionCompleteTime != null && (
|
|
89
|
+
<View style={s.metaItem}>
|
|
90
|
+
<Text style={s.metaLabel}>Duration</Text>
|
|
91
|
+
<Text style={s.metaValue}>{item.actionCompleteTime}ms</Text>
|
|
92
|
+
</View>
|
|
93
|
+
)}
|
|
94
|
+
</View>
|
|
95
|
+
|
|
96
|
+
{changes.length > 0 && (
|
|
97
|
+
<View style={s.changesCard}>
|
|
98
|
+
<Text style={s.changesTitle}>Changed Keys</Text>
|
|
99
|
+
<View style={s.changesTags}>
|
|
100
|
+
{changes.map((key) => (
|
|
101
|
+
<View key={key} style={s.changeTag}>
|
|
102
|
+
<Text style={s.changeTagText}>{key}</Text>
|
|
103
|
+
</View>
|
|
104
|
+
))}
|
|
105
|
+
</View>
|
|
106
|
+
</View>
|
|
107
|
+
)}
|
|
108
|
+
|
|
109
|
+
<CollapsibleSection title="Previous State">
|
|
110
|
+
<View style={s.sectionWithCopy}>
|
|
111
|
+
<CopyButton text={safeStringify(item.prevState, 2)} label="Previous State" />
|
|
112
|
+
<JsonView data={item.prevState} maxHeight={250} />
|
|
113
|
+
</View>
|
|
114
|
+
</CollapsibleSection>
|
|
115
|
+
|
|
116
|
+
<CollapsibleSection title="Next State" initiallyExpanded>
|
|
117
|
+
<View style={s.sectionWithCopy}>
|
|
118
|
+
<CopyButton text={safeStringify(item.nextState, 2)} label="Next State" />
|
|
119
|
+
<JsonView data={item.nextState} maxHeight={250} />
|
|
120
|
+
</View>
|
|
121
|
+
</CollapsibleSection>
|
|
122
|
+
</ScrollView>
|
|
123
|
+
);
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
));
|
|
127
|
+
|
|
128
|
+
const s = StyleSheet.create({
|
|
129
|
+
// Row
|
|
130
|
+
cardRow: { flexDirection: 'row', padding: 14, alignItems: 'center' },
|
|
131
|
+
actionIcon: {
|
|
132
|
+
width: 28,
|
|
133
|
+
height: 28,
|
|
134
|
+
borderRadius: 8,
|
|
135
|
+
alignItems: 'center',
|
|
136
|
+
justifyContent: 'center',
|
|
137
|
+
marginRight: 12,
|
|
138
|
+
},
|
|
139
|
+
actionDot: { width: 8, height: 8, borderRadius: 4 },
|
|
140
|
+
cardContent: { flex: 1 },
|
|
141
|
+
cardMeta: { flexDirection: 'row', alignItems: 'center', gap: 8, marginBottom: 3 },
|
|
142
|
+
action: { fontSize: 15, fontWeight: '600', color: Colors.text },
|
|
143
|
+
storeBadge: {
|
|
144
|
+
backgroundColor: 'rgba(0,122,255,0.08)',
|
|
145
|
+
paddingHorizontal: 8,
|
|
146
|
+
paddingVertical: 2,
|
|
147
|
+
borderRadius: 4,
|
|
148
|
+
},
|
|
149
|
+
storeBadgeText: { fontSize: 11, color: Colors.primary, fontWeight: '600' },
|
|
150
|
+
time: { fontSize: 12, color: Colors.textSecondary },
|
|
151
|
+
durationBadge: {
|
|
152
|
+
backgroundColor: Colors.background,
|
|
153
|
+
borderRadius: 8,
|
|
154
|
+
paddingHorizontal: 8,
|
|
155
|
+
paddingVertical: 4,
|
|
156
|
+
},
|
|
157
|
+
durationText: { fontSize: 12, color: Colors.textSecondary, fontWeight: '500' },
|
|
158
|
+
|
|
159
|
+
// Detail header
|
|
160
|
+
detailHeaderCenter: {
|
|
161
|
+
flexDirection: 'row',
|
|
162
|
+
alignItems: 'center',
|
|
163
|
+
gap: 10,
|
|
164
|
+
flex: 1,
|
|
165
|
+
},
|
|
166
|
+
detailAction: { fontSize: 17, fontWeight: '700' },
|
|
167
|
+
|
|
168
|
+
// Detail body
|
|
169
|
+
detailBody: { flex: 1 },
|
|
170
|
+
detailBodyContent: { padding: 12, paddingBottom: 40 },
|
|
171
|
+
sectionWithCopy: { gap: 8 },
|
|
172
|
+
|
|
173
|
+
// Meta
|
|
174
|
+
metaCard: {
|
|
175
|
+
backgroundColor: Colors.surface,
|
|
176
|
+
borderRadius: 12,
|
|
177
|
+
padding: 14,
|
|
178
|
+
marginBottom: 8,
|
|
179
|
+
flexDirection: 'row',
|
|
180
|
+
alignItems: 'center',
|
|
181
|
+
},
|
|
182
|
+
metaItem: { flex: 1 },
|
|
183
|
+
metaDivider: { width: 1, height: 28, backgroundColor: Colors.border, marginHorizontal: 12 },
|
|
184
|
+
metaLabel: { fontSize: 11, color: Colors.textSecondary, fontWeight: '600', textTransform: 'uppercase', marginBottom: 2 },
|
|
185
|
+
metaValue: { fontSize: 14, color: Colors.text, fontWeight: '500' },
|
|
186
|
+
|
|
187
|
+
// Changes
|
|
188
|
+
changesCard: {
|
|
189
|
+
backgroundColor: Colors.surface,
|
|
190
|
+
borderRadius: 12,
|
|
191
|
+
padding: 14,
|
|
192
|
+
marginBottom: 8,
|
|
193
|
+
},
|
|
194
|
+
changesTitle: { fontSize: 13, fontWeight: '600', color: Colors.textSecondary, marginBottom: 10 },
|
|
195
|
+
changesTags: { flexDirection: 'row', flexWrap: 'wrap', gap: 6 },
|
|
196
|
+
changeTag: {
|
|
197
|
+
backgroundColor: 'rgba(0,122,255,0.08)',
|
|
198
|
+
paddingHorizontal: 10,
|
|
199
|
+
paddingVertical: 4,
|
|
200
|
+
borderRadius: 6,
|
|
201
|
+
},
|
|
202
|
+
changeTagText: { fontSize: 12, color: Colors.primary, fontWeight: '600' },
|
|
203
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { View, Text, Pressable, StyleSheet, Animated } from 'react-native';
|
|
3
|
+
import { Colors } from '../../utils/colors';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
title: string;
|
|
7
|
+
initiallyExpanded?: boolean;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const CollapsibleSection: React.FC<Props> = ({
|
|
12
|
+
title,
|
|
13
|
+
initiallyExpanded = false,
|
|
14
|
+
children,
|
|
15
|
+
}) => {
|
|
16
|
+
const [expanded, setExpanded] = useState(initiallyExpanded);
|
|
17
|
+
const [rotationAnim] = useState(() => new Animated.Value(initiallyExpanded ? 1 : 0));
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
Animated.timing(rotationAnim, {
|
|
21
|
+
toValue: expanded ? 1 : 0,
|
|
22
|
+
duration: 200,
|
|
23
|
+
useNativeDriver: true,
|
|
24
|
+
}).start();
|
|
25
|
+
}, [expanded, rotationAnim]);
|
|
26
|
+
|
|
27
|
+
const chevronRotation = rotationAnim.interpolate({
|
|
28
|
+
inputRange: [0, 1],
|
|
29
|
+
outputRange: ['0deg', '90deg'],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<View style={styles.section}>
|
|
34
|
+
<Pressable
|
|
35
|
+
style={styles.header}
|
|
36
|
+
onPress={() => setExpanded(!expanded)}
|
|
37
|
+
>
|
|
38
|
+
<Text style={styles.title}>{title}</Text>
|
|
39
|
+
<Animated.Text style={[styles.chevron, { transform: [{ rotate: chevronRotation }] }]}>
|
|
40
|
+
›
|
|
41
|
+
</Animated.Text>
|
|
42
|
+
</Pressable>
|
|
43
|
+
{expanded && <View style={styles.body}>{children}</View>}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const styles = StyleSheet.create({
|
|
49
|
+
section: {
|
|
50
|
+
backgroundColor: Colors.surface,
|
|
51
|
+
borderRadius: 12,
|
|
52
|
+
marginBottom: 8,
|
|
53
|
+
overflow: 'hidden',
|
|
54
|
+
},
|
|
55
|
+
header: {
|
|
56
|
+
flexDirection: 'row',
|
|
57
|
+
justifyContent: 'space-between',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
paddingHorizontal: 16,
|
|
60
|
+
paddingVertical: 13,
|
|
61
|
+
},
|
|
62
|
+
title: {
|
|
63
|
+
fontSize: 15,
|
|
64
|
+
fontWeight: '600',
|
|
65
|
+
color: Colors.text,
|
|
66
|
+
},
|
|
67
|
+
chevron: {
|
|
68
|
+
fontSize: 20,
|
|
69
|
+
fontWeight: '500',
|
|
70
|
+
color: Colors.textLight,
|
|
71
|
+
width: 20,
|
|
72
|
+
textAlign: 'center',
|
|
73
|
+
},
|
|
74
|
+
body: {
|
|
75
|
+
paddingHorizontal: 16,
|
|
76
|
+
paddingBottom: 14,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet } from 'react-native';
|
|
3
|
+
import { Colors } from '../../utils/colors';
|
|
4
|
+
import { copyToComputer } from '../../utils/copyToComputer';
|
|
5
|
+
|
|
6
|
+
interface CopyButtonProps {
|
|
7
|
+
/** Content to copy */
|
|
8
|
+
text: string;
|
|
9
|
+
/** Label for console.log identification */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Compact mode for inline use */
|
|
12
|
+
compact?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CopyButton: React.FC<CopyButtonProps> = ({ text, label, compact }) => {
|
|
16
|
+
const [feedback, setFeedback] = useState<'copied' | 'logged' | null>(null);
|
|
17
|
+
|
|
18
|
+
const handleCopy = useCallback(() => {
|
|
19
|
+
try {
|
|
20
|
+
const result = copyToComputer(text, { label });
|
|
21
|
+
setFeedback(result.method === 'clipboard' ? 'copied' : 'logged');
|
|
22
|
+
} catch {
|
|
23
|
+
setFeedback('logged');
|
|
24
|
+
}
|
|
25
|
+
setTimeout(() => setFeedback(null), 2000);
|
|
26
|
+
}, [text, label]);
|
|
27
|
+
|
|
28
|
+
if (!text) return null;
|
|
29
|
+
|
|
30
|
+
const feedbackLabel =
|
|
31
|
+
feedback === 'copied' ? 'Copied' :
|
|
32
|
+
feedback === 'logged' ? 'Logged' :
|
|
33
|
+
null;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<TouchableOpacity
|
|
37
|
+
style={[s.copyBtn, compact && s.copyBtnCompact]}
|
|
38
|
+
onPress={handleCopy}
|
|
39
|
+
activeOpacity={0.7}
|
|
40
|
+
>
|
|
41
|
+
<Text style={[s.copyBtnText, compact && s.copyBtnTextCompact]}>
|
|
42
|
+
{feedbackLabel ?? 'Copy'}
|
|
43
|
+
</Text>
|
|
44
|
+
</TouchableOpacity>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const s = StyleSheet.create({
|
|
49
|
+
copyBtn: {
|
|
50
|
+
backgroundColor: Colors.background,
|
|
51
|
+
paddingHorizontal: 12,
|
|
52
|
+
paddingVertical: 5,
|
|
53
|
+
borderRadius: 8,
|
|
54
|
+
alignSelf: 'flex-end',
|
|
55
|
+
},
|
|
56
|
+
copyBtnCompact: {
|
|
57
|
+
paddingHorizontal: 8,
|
|
58
|
+
paddingVertical: 3,
|
|
59
|
+
},
|
|
60
|
+
copyBtnText: {
|
|
61
|
+
fontSize: 12,
|
|
62
|
+
color: Colors.textSecondary,
|
|
63
|
+
fontWeight: '500',
|
|
64
|
+
},
|
|
65
|
+
copyBtnTextCompact: {
|
|
66
|
+
fontSize: 11,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text, ScrollView, StyleSheet } from 'react-native';
|
|
3
|
+
import { safeStringify } from '../../utils/safeStringify';
|
|
4
|
+
|
|
5
|
+
const MAX_DEPTH = 3;
|
|
6
|
+
const MAX_CHILDREN = 50;
|
|
7
|
+
|
|
8
|
+
export const JsonView: React.FC<{ data: unknown; maxHeight?: number }> = React.memo(({
|
|
9
|
+
data,
|
|
10
|
+
maxHeight,
|
|
11
|
+
}) => {
|
|
12
|
+
return (
|
|
13
|
+
<ScrollView
|
|
14
|
+
style={[s.scroll, maxHeight != null && { maxHeight }]}
|
|
15
|
+
nestedScrollEnabled
|
|
16
|
+
bounces={false}
|
|
17
|
+
showsVerticalScrollIndicator
|
|
18
|
+
>
|
|
19
|
+
<View style={s.block}>
|
|
20
|
+
<Node value={data} depth={0} isLast />
|
|
21
|
+
</View>
|
|
22
|
+
</ScrollView>
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const Node: React.FC<{
|
|
27
|
+
value: unknown;
|
|
28
|
+
depth: number;
|
|
29
|
+
isLast: boolean;
|
|
30
|
+
}> = ({ value, depth, isLast }) => {
|
|
31
|
+
const comma = isLast ? '' : ',';
|
|
32
|
+
|
|
33
|
+
if (value === null) return <C color="#F38BA8">{`null${comma}`}</C>;
|
|
34
|
+
if (value === undefined) return <C color="#F38BA8">{`undefined${comma}`}</C>;
|
|
35
|
+
if (typeof value === 'boolean') return <C color="#89B4FA">{`${String(value)}${comma}`}</C>;
|
|
36
|
+
if (typeof value === 'number') return <C color="#CBA6F7">{`${value}${comma}`}</C>;
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
const display = value.length > 500 ? value.slice(0, 500) + '...' : value;
|
|
39
|
+
return <C color="#A6E3A1" selectable>{`"${display}"${comma}`}</C>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (depth >= MAX_DEPTH) {
|
|
43
|
+
const collapsed = truncate(safeStringify(value), 200);
|
|
44
|
+
return <C color="#6C7086">{`${collapsed}${comma}`}</C>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const entries = Object.entries(value as Record<string, unknown>);
|
|
48
|
+
const isArray = Array.isArray(value);
|
|
49
|
+
const open = isArray ? '[' : '{';
|
|
50
|
+
const close = isArray ? ']' : '}';
|
|
51
|
+
|
|
52
|
+
if (entries.length === 0) return <C color="#6C7086">{`${open}${close}${comma}`}</C>;
|
|
53
|
+
|
|
54
|
+
const limited = entries.slice(0, MAX_CHILDREN);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<View style={depth > 0 ? s.indent : undefined}>
|
|
58
|
+
<C color="#6C7086">{open}</C>
|
|
59
|
+
{limited.map(([key, val], i) => (
|
|
60
|
+
<View key={key} style={s.line}>
|
|
61
|
+
<Text style={s.row}>
|
|
62
|
+
{!isArray && <Text style={s.key}>"{key}"</Text>}
|
|
63
|
+
{!isArray && <Text style={s.colon}>{': '}</Text>}
|
|
64
|
+
</Text>
|
|
65
|
+
<Node
|
|
66
|
+
value={val}
|
|
67
|
+
depth={depth + 1}
|
|
68
|
+
isLast={i === limited.length - 1}
|
|
69
|
+
/>
|
|
70
|
+
</View>
|
|
71
|
+
))}
|
|
72
|
+
{entries.length > MAX_CHILDREN && (
|
|
73
|
+
<C color="#6C7086">{` ... ${entries.length - MAX_CHILDREN} more`}</C>
|
|
74
|
+
)}
|
|
75
|
+
<C color="#6C7086">{`${close}${comma}`}</C>
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const C: React.FC<{ color: string; children: string; selectable?: boolean }> = ({
|
|
81
|
+
color,
|
|
82
|
+
children,
|
|
83
|
+
selectable,
|
|
84
|
+
}) => (
|
|
85
|
+
<Text style={[s.node, { color }]} selectable={selectable}>
|
|
86
|
+
{children}
|
|
87
|
+
</Text>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
function truncate(str: string, len: number): string {
|
|
91
|
+
return str.length > len ? str.slice(0, len) + '...' : str;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const s = StyleSheet.create({
|
|
95
|
+
scroll: {
|
|
96
|
+
backgroundColor: '#1E1E2E',
|
|
97
|
+
borderRadius: 12,
|
|
98
|
+
padding: 12,
|
|
99
|
+
},
|
|
100
|
+
block: {},
|
|
101
|
+
node: {
|
|
102
|
+
fontFamily: 'Courier',
|
|
103
|
+
fontSize: 12,
|
|
104
|
+
lineHeight: 18,
|
|
105
|
+
color: '#CDD6F4',
|
|
106
|
+
},
|
|
107
|
+
indent: {
|
|
108
|
+
paddingLeft: 16,
|
|
109
|
+
},
|
|
110
|
+
line: {
|
|
111
|
+
flexDirection: 'row',
|
|
112
|
+
flexWrap: 'wrap',
|
|
113
|
+
},
|
|
114
|
+
row: {},
|
|
115
|
+
key: {
|
|
116
|
+
fontFamily: 'Courier',
|
|
117
|
+
fontSize: 12,
|
|
118
|
+
color: '#89DCEB',
|
|
119
|
+
},
|
|
120
|
+
colon: {
|
|
121
|
+
fontFamily: 'Courier',
|
|
122
|
+
fontSize: 12,
|
|
123
|
+
color: '#CDD6F4',
|
|
124
|
+
},
|
|
125
|
+
});
|