react-native-debug-toolkit 0.6.4 → 2.0.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.
Files changed (277) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -212
  3. package/lib/commonjs/components/ClipboardTab.js +92 -0
  4. package/lib/commonjs/components/ClipboardTab.js.map +1 -0
  5. package/lib/commonjs/components/ConsoleLogTab.js +295 -0
  6. package/lib/commonjs/components/ConsoleLogTab.js.map +1 -0
  7. package/lib/commonjs/components/EnvironmentTab.js +288 -0
  8. package/lib/commonjs/components/EnvironmentTab.js.map +1 -0
  9. package/lib/commonjs/components/FloatPanelView.js +797 -0
  10. package/lib/commonjs/components/FloatPanelView.js.map +1 -0
  11. package/lib/commonjs/components/NavigationLogTab.js +131 -0
  12. package/lib/commonjs/components/NavigationLogTab.js.map +1 -0
  13. package/lib/commonjs/components/NetworkLogTab.js +575 -0
  14. package/lib/commonjs/components/NetworkLogTab.js.map +1 -0
  15. package/lib/commonjs/components/ThirdPartyLibsTab.js +97 -0
  16. package/lib/commonjs/components/ThirdPartyLibsTab.js.map +1 -0
  17. package/lib/commonjs/components/TrackLogTab.js +372 -0
  18. package/lib/commonjs/components/TrackLogTab.js.map +1 -0
  19. package/lib/commonjs/components/ZustandLogTab.js +451 -0
  20. package/lib/commonjs/components/ZustandLogTab.js.map +1 -0
  21. package/lib/commonjs/components/shared/CollapsibleSection.js +84 -0
  22. package/lib/commonjs/components/shared/CollapsibleSection.js.map +1 -0
  23. package/lib/commonjs/components/shared/CopyButton.js +64 -0
  24. package/lib/commonjs/components/shared/CopyButton.js.map +1 -0
  25. package/lib/commonjs/components/shared/JsonView.js +157 -0
  26. package/lib/commonjs/components/shared/JsonView.js.map +1 -0
  27. package/lib/commonjs/core/DebugToolkit.js +142 -0
  28. package/lib/commonjs/core/DebugToolkit.js.map +1 -0
  29. package/lib/commonjs/core/DebugToolkitProvider.js +64 -0
  30. package/lib/commonjs/core/DebugToolkitProvider.js.map +1 -0
  31. package/lib/commonjs/features/ClipboardFeature.js +17 -0
  32. package/lib/commonjs/features/ClipboardFeature.js.map +1 -0
  33. package/lib/commonjs/features/ConsoleLogFeature.js +98 -0
  34. package/lib/commonjs/features/ConsoleLogFeature.js.map +1 -0
  35. package/lib/commonjs/features/EnvironmentFeature.js +168 -0
  36. package/lib/commonjs/features/EnvironmentFeature.js.map +1 -0
  37. package/lib/commonjs/features/NavigationLogFeature.js +60 -0
  38. package/lib/commonjs/features/NavigationLogFeature.js.map +1 -0
  39. package/lib/commonjs/features/NetworkFeature.js +328 -0
  40. package/lib/commonjs/features/NetworkFeature.js.map +1 -0
  41. package/lib/commonjs/features/ThirdPartyLibsFeature.js +51 -0
  42. package/lib/commonjs/features/ThirdPartyLibsFeature.js.map +1 -0
  43. package/lib/commonjs/features/TrackFeature.js +55 -0
  44. package/lib/commonjs/features/TrackFeature.js.map +1 -0
  45. package/lib/commonjs/features/ZustandLogFeature.js +76 -0
  46. package/lib/commonjs/features/ZustandLogFeature.js.map +1 -0
  47. package/lib/commonjs/hooks/useNavigationLogger.js +78 -0
  48. package/lib/commonjs/hooks/useNavigationLogger.js.map +1 -0
  49. package/lib/commonjs/hooks/useSlideDetailAnimation.js +53 -0
  50. package/lib/commonjs/hooks/useSlideDetailAnimation.js.map +1 -0
  51. package/lib/commonjs/index.js +165 -0
  52. package/lib/commonjs/index.js.map +1 -0
  53. package/lib/commonjs/initialize.js +161 -0
  54. package/lib/commonjs/initialize.js.map +1 -0
  55. package/lib/commonjs/native/NativeDebugLibs.js +58 -0
  56. package/lib/commonjs/native/NativeDebugLibs.js.map +1 -0
  57. package/lib/commonjs/package.json +1 -0
  58. package/lib/commonjs/types/index.js +6 -0
  59. package/lib/commonjs/types/index.js.map +1 -0
  60. package/lib/commonjs/utils/constants.js +135 -0
  61. package/lib/commonjs/utils/constants.js.map +1 -0
  62. package/lib/commonjs/utils/copyToComputer.js +97 -0
  63. package/lib/commonjs/utils/copyToComputer.js.map +1 -0
  64. package/lib/commonjs/utils/createEventChannel.js +21 -0
  65. package/lib/commonjs/utils/createEventChannel.js.map +1 -0
  66. package/lib/commonjs/utils/createObservableStore.js +38 -0
  67. package/lib/commonjs/utils/createObservableStore.js.map +1 -0
  68. package/lib/commonjs/utils/safeStringify.js +27 -0
  69. package/lib/commonjs/utils/safeStringify.js.map +1 -0
  70. package/lib/module/components/ClipboardTab.js +86 -0
  71. package/lib/module/components/ClipboardTab.js.map +1 -0
  72. package/lib/module/components/ConsoleLogTab.js +290 -0
  73. package/lib/module/components/ConsoleLogTab.js.map +1 -0
  74. package/lib/module/components/EnvironmentTab.js +282 -0
  75. package/lib/module/components/EnvironmentTab.js.map +1 -0
  76. package/lib/module/components/FloatPanelView.js +791 -0
  77. package/lib/module/components/FloatPanelView.js.map +1 -0
  78. package/lib/module/components/NavigationLogTab.js +126 -0
  79. package/lib/module/components/NavigationLogTab.js.map +1 -0
  80. package/lib/module/components/NetworkLogTab.js +570 -0
  81. package/lib/module/components/NetworkLogTab.js.map +1 -0
  82. package/lib/module/components/ThirdPartyLibsTab.js +91 -0
  83. package/lib/module/components/ThirdPartyLibsTab.js.map +1 -0
  84. package/lib/module/components/TrackLogTab.js +367 -0
  85. package/lib/module/components/TrackLogTab.js.map +1 -0
  86. package/lib/module/components/ZustandLogTab.js +446 -0
  87. package/lib/module/components/ZustandLogTab.js.map +1 -0
  88. package/lib/module/components/shared/CollapsibleSection.js +78 -0
  89. package/lib/module/components/shared/CollapsibleSection.js.map +1 -0
  90. package/lib/module/components/shared/CopyButton.js +58 -0
  91. package/lib/module/components/shared/CopyButton.js.map +1 -0
  92. package/lib/module/components/shared/JsonView.js +152 -0
  93. package/lib/module/components/shared/JsonView.js.map +1 -0
  94. package/lib/module/core/DebugToolkit.js +137 -0
  95. package/lib/module/core/DebugToolkit.js.map +1 -0
  96. package/lib/module/core/DebugToolkitProvider.js +58 -0
  97. package/lib/module/core/DebugToolkitProvider.js.map +1 -0
  98. package/lib/module/features/ClipboardFeature.js +12 -0
  99. package/lib/module/features/ClipboardFeature.js.map +1 -0
  100. package/lib/module/features/ConsoleLogFeature.js +93 -0
  101. package/lib/module/features/ConsoleLogFeature.js.map +1 -0
  102. package/lib/module/features/EnvironmentFeature.js +164 -0
  103. package/lib/module/features/EnvironmentFeature.js.map +1 -0
  104. package/lib/module/features/NavigationLogFeature.js +54 -0
  105. package/lib/module/features/NavigationLogFeature.js.map +1 -0
  106. package/lib/module/features/NetworkFeature.js +322 -0
  107. package/lib/module/features/NetworkFeature.js.map +1 -0
  108. package/lib/module/features/ThirdPartyLibsFeature.js +46 -0
  109. package/lib/module/features/ThirdPartyLibsFeature.js.map +1 -0
  110. package/lib/module/features/TrackFeature.js +49 -0
  111. package/lib/module/features/TrackFeature.js.map +1 -0
  112. package/lib/module/features/ZustandLogFeature.js +69 -0
  113. package/lib/module/features/ZustandLogFeature.js.map +1 -0
  114. package/lib/module/hooks/useNavigationLogger.js +74 -0
  115. package/lib/module/hooks/useNavigationLogger.js.map +1 -0
  116. package/lib/module/hooks/useSlideDetailAnimation.js +50 -0
  117. package/lib/module/hooks/useSlideDetailAnimation.js.map +1 -0
  118. package/lib/module/index.js +29 -0
  119. package/lib/module/index.js.map +1 -0
  120. package/lib/module/initialize.js +156 -0
  121. package/lib/module/initialize.js.map +1 -0
  122. package/lib/module/native/NativeDebugLibs.js +54 -0
  123. package/lib/module/native/NativeDebugLibs.js.map +1 -0
  124. package/lib/module/package.json +1 -0
  125. package/lib/module/types/index.js +4 -0
  126. package/lib/module/types/index.js.map +1 -0
  127. package/lib/module/utils/constants.js +130 -0
  128. package/lib/module/utils/constants.js.map +1 -0
  129. package/lib/module/utils/copyToComputer.js +91 -0
  130. package/lib/module/utils/copyToComputer.js.map +1 -0
  131. package/lib/module/utils/createEventChannel.js +17 -0
  132. package/lib/module/utils/createEventChannel.js.map +1 -0
  133. package/lib/module/utils/createObservableStore.js +34 -0
  134. package/lib/module/utils/createObservableStore.js.map +1 -0
  135. package/lib/module/utils/safeStringify.js +23 -0
  136. package/lib/module/utils/safeStringify.js.map +1 -0
  137. package/lib/typescript/src/components/ClipboardTab.d.ts +4 -0
  138. package/lib/typescript/src/components/ClipboardTab.d.ts.map +1 -0
  139. package/lib/typescript/src/components/ConsoleLogTab.d.ts +4 -0
  140. package/lib/typescript/src/components/ConsoleLogTab.d.ts.map +1 -0
  141. package/lib/typescript/src/components/EnvironmentTab.d.ts +4 -0
  142. package/lib/typescript/src/components/EnvironmentTab.d.ts.map +1 -0
  143. package/lib/typescript/src/components/FloatPanelView.d.ts +64 -0
  144. package/lib/typescript/src/components/FloatPanelView.d.ts.map +1 -0
  145. package/lib/typescript/src/components/NavigationLogTab.d.ts +4 -0
  146. package/lib/typescript/src/components/NavigationLogTab.d.ts.map +1 -0
  147. package/lib/typescript/src/components/NetworkLogTab.d.ts +4 -0
  148. package/lib/typescript/src/components/NetworkLogTab.d.ts.map +1 -0
  149. package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts +4 -0
  150. package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts.map +1 -0
  151. package/lib/typescript/src/components/TrackLogTab.d.ts +4 -0
  152. package/lib/typescript/src/components/TrackLogTab.d.ts.map +1 -0
  153. package/lib/typescript/src/components/ZustandLogTab.d.ts +4 -0
  154. package/lib/typescript/src/components/ZustandLogTab.d.ts.map +1 -0
  155. package/lib/typescript/src/components/shared/CollapsibleSection.d.ts +9 -0
  156. package/lib/typescript/src/components/shared/CollapsibleSection.d.ts.map +1 -0
  157. package/lib/typescript/src/components/shared/CopyButton.d.ts +12 -0
  158. package/lib/typescript/src/components/shared/CopyButton.d.ts.map +1 -0
  159. package/lib/typescript/src/components/shared/JsonView.d.ts +6 -0
  160. package/lib/typescript/src/components/shared/JsonView.d.ts.map +1 -0
  161. package/lib/typescript/src/core/DebugToolkit.d.ts +27 -0
  162. package/lib/typescript/src/core/DebugToolkit.d.ts.map +1 -0
  163. package/lib/typescript/src/core/DebugToolkitProvider.d.ts +18 -0
  164. package/lib/typescript/src/core/DebugToolkitProvider.d.ts.map +1 -0
  165. package/lib/typescript/src/features/ClipboardFeature.d.ts +3 -0
  166. package/lib/typescript/src/features/ClipboardFeature.d.ts.map +1 -0
  167. package/lib/typescript/src/features/ConsoleLogFeature.d.ts +7 -0
  168. package/lib/typescript/src/features/ConsoleLogFeature.d.ts.map +1 -0
  169. package/lib/typescript/src/features/EnvironmentFeature.d.ts +8 -0
  170. package/lib/typescript/src/features/EnvironmentFeature.d.ts.map +1 -0
  171. package/lib/typescript/src/features/NavigationLogFeature.d.ts +8 -0
  172. package/lib/typescript/src/features/NavigationLogFeature.d.ts.map +1 -0
  173. package/lib/typescript/src/features/NetworkFeature.d.ts +28 -0
  174. package/lib/typescript/src/features/NetworkFeature.d.ts.map +1 -0
  175. package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts +3 -0
  176. package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts.map +1 -0
  177. package/lib/typescript/src/features/TrackFeature.d.ts +12 -0
  178. package/lib/typescript/src/features/TrackFeature.d.ts.map +1 -0
  179. package/lib/typescript/src/features/ZustandLogFeature.d.ts +29 -0
  180. package/lib/typescript/src/features/ZustandLogFeature.d.ts.map +1 -0
  181. package/lib/typescript/src/hooks/useNavigationLogger.d.ts +20 -0
  182. package/lib/typescript/src/hooks/useNavigationLogger.d.ts.map +1 -0
  183. package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts +11 -0
  184. package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts.map +1 -0
  185. package/lib/typescript/src/index.d.ts +26 -0
  186. package/lib/typescript/src/index.d.ts.map +1 -0
  187. package/lib/typescript/src/initialize.d.ts +51 -0
  188. package/lib/typescript/src/initialize.d.ts.map +1 -0
  189. package/lib/typescript/src/native/NativeDebugLibs.d.ts +11 -0
  190. package/lib/typescript/src/native/NativeDebugLibs.d.ts.map +1 -0
  191. package/lib/typescript/src/types/index.d.ts +112 -0
  192. package/lib/typescript/src/types/index.d.ts.map +1 -0
  193. package/lib/typescript/src/utils/constants.d.ts +96 -0
  194. package/lib/typescript/src/utils/constants.d.ts.map +1 -0
  195. package/lib/typescript/src/utils/copyToComputer.d.ts +30 -0
  196. package/lib/typescript/src/utils/copyToComputer.d.ts.map +1 -0
  197. package/lib/typescript/src/utils/createEventChannel.d.ts +7 -0
  198. package/lib/typescript/src/utils/createEventChannel.d.ts.map +1 -0
  199. package/lib/typescript/src/utils/createObservableStore.d.ts +9 -0
  200. package/lib/typescript/src/utils/createObservableStore.d.ts.map +1 -0
  201. package/lib/typescript/src/utils/safeStringify.d.ts +6 -0
  202. package/lib/typescript/src/utils/safeStringify.d.ts.map +1 -0
  203. package/package.json +63 -24
  204. package/src/components/ClipboardTab.tsx +81 -0
  205. package/src/components/ConsoleLogTab.tsx +209 -0
  206. package/src/components/EnvironmentTab.tsx +276 -0
  207. package/src/components/FloatPanelView.tsx +714 -0
  208. package/src/components/NavigationLogTab.tsx +66 -0
  209. package/src/components/NetworkLogTab.tsx +411 -0
  210. package/src/components/ThirdPartyLibsTab.tsx +63 -0
  211. package/src/components/TrackLogTab.tsx +245 -0
  212. package/src/components/ZustandLogTab.tsx +305 -0
  213. package/src/components/shared/CollapsibleSection.tsx +78 -0
  214. package/src/components/shared/CopyButton.tsx +68 -0
  215. package/src/components/shared/JsonView.tsx +125 -0
  216. package/src/core/DebugToolkit.tsx +174 -0
  217. package/src/core/DebugToolkitProvider.tsx +89 -0
  218. package/src/features/ClipboardFeature.ts +11 -0
  219. package/src/features/ConsoleLogFeature.ts +118 -0
  220. package/src/features/EnvironmentFeature.ts +194 -0
  221. package/src/features/NavigationLogFeature.ts +74 -0
  222. package/src/features/NetworkFeature.ts +488 -0
  223. package/src/features/ThirdPartyLibsFeature.ts +42 -0
  224. package/src/features/TrackFeature.ts +69 -0
  225. package/src/features/ZustandLogFeature.ts +127 -0
  226. package/src/hooks/useNavigationLogger.ts +107 -0
  227. package/src/hooks/useSlideDetailAnimation.ts +45 -0
  228. package/src/index.ts +52 -0
  229. package/src/initialize.ts +214 -0
  230. package/src/native/NativeDebugLibs.ts +74 -0
  231. package/src/types/index.ts +138 -0
  232. package/src/utils/constants.ts +91 -0
  233. package/src/utils/copyToComputer.ts +104 -0
  234. package/src/utils/createEventChannel.ts +22 -0
  235. package/src/utils/createObservableStore.ts +42 -0
  236. package/src/utils/safeStringify.ts +25 -0
  237. package/.cursor/rules/react-native.mdc +0 -41
  238. package/README.zh-CN.md +0 -230
  239. package/index.js +0 -41
  240. package/ios/BuildTypeModule.h +0 -9
  241. package/ios/BuildTypeModule.m +0 -42
  242. package/ios/RNDebugLibs.h +0 -10
  243. package/ios/RNDebugLibs.m +0 -79
  244. package/lib/DebugToolKit.js +0 -126
  245. package/lib/EnvironmentManager.ts +0 -80
  246. package/lib/NativeDebugLibs.js +0 -67
  247. package/lib/features/ConsoleLogFeature.js +0 -70
  248. package/lib/features/NavigationLogFeature.js +0 -45
  249. package/lib/features/NetworkFeature.js +0 -389
  250. package/lib/features/PerformanceFeature.js +0 -390
  251. package/lib/features/ThirdPartyLibsFeature.js +0 -63
  252. package/lib/features/TrackFeature.js +0 -94
  253. package/lib/features/ZustandLogFeature.js +0 -44
  254. package/lib/hooks/useNavigationLogger.js +0 -92
  255. package/lib/index.js +0 -114
  256. package/lib/navigation/NavigationLogger.js +0 -1
  257. package/lib/types/TrackTypes.ts +0 -92
  258. package/lib/utils/DebugConst.js +0 -67
  259. package/lib/utils/StorageUtils.js +0 -80
  260. package/lib/views/ConsoleLogDetails.js +0 -314
  261. package/lib/views/FloatPanelView.js +0 -697
  262. package/lib/views/HttpLogDetails.js +0 -648
  263. package/lib/views/NavigationLogDetails.js +0 -302
  264. package/lib/views/RestartModal.js +0 -75
  265. package/lib/views/SubViewConsoleLogs.js +0 -209
  266. package/lib/views/SubViewEnvironment.js +0 -73
  267. package/lib/views/SubViewHTTPLogs.js +0 -235
  268. package/lib/views/SubViewNavigationLogs.js +0 -199
  269. package/lib/views/SubViewPerformance.js +0 -515
  270. package/lib/views/SubViewThirdPartyLibs.js +0 -239
  271. package/lib/views/SubViewTrackLogs.js +0 -318
  272. package/lib/views/SubViewZustandLogs.js +0 -279
  273. package/lib/views/TabView.js +0 -66
  274. package/lib/views/TrackLogDetails.js +0 -481
  275. package/lib/views/ZustandLogDetails.js +0 -355
  276. package/react-native-debug-toolkit.podspec +0 -25
  277. package/react-native.config.js +0 -18
@@ -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
+ });
@@ -0,0 +1,174 @@
1
+ import type { DebugFeature } from '../types';
2
+
3
+ export class DebugToolkit {
4
+ private static instance: DebugToolkit | null = null;
5
+ private _features: DebugFeature[] = [];
6
+ private _enabled: boolean;
7
+ private _panelVisible: boolean = false;
8
+ private renderCallback: (() => void) | null = null;
9
+
10
+ private constructor(enabled = true) {
11
+ this._enabled = enabled;
12
+ }
13
+
14
+ static getInstance(enabled = true): DebugToolkit {
15
+ if (!DebugToolkit.instance) {
16
+ DebugToolkit.instance = new DebugToolkit(enabled);
17
+ } else {
18
+ DebugToolkit.instance._enabled = enabled;
19
+ }
20
+ return DebugToolkit.instance;
21
+ }
22
+
23
+ get features(): DebugFeature[] {
24
+ return [...this._features];
25
+ }
26
+
27
+ get enabled(): boolean {
28
+ return this._enabled;
29
+ }
30
+
31
+ get panelVisible(): boolean {
32
+ return this._panelVisible;
33
+ }
34
+
35
+ registerRenderCallback(cb: () => void): void {
36
+ if (this.renderCallback) {
37
+ console.warn(
38
+ '[DebugToolkit] A render callback is already registered. Overwriting. ' +
39
+ 'Make sure only one <DebugToolkitProvider> is mounted at a time.',
40
+ );
41
+ }
42
+ this.renderCallback = cb;
43
+ }
44
+
45
+ unregisterRenderCallback(): void {
46
+ this.renderCallback = null;
47
+ }
48
+
49
+ setEnabled(enabled: boolean): void {
50
+ if (this._enabled === enabled) {
51
+ return;
52
+ }
53
+
54
+ this._enabled = enabled;
55
+
56
+ if (!enabled) {
57
+ this.hidePanel();
58
+ this._features.forEach((feature) => feature.cleanup?.());
59
+ this._features = [];
60
+ }
61
+ }
62
+
63
+ private updatePanel(): void {
64
+ this.renderCallback?.();
65
+ }
66
+
67
+ addFeature(feature: DebugFeature): void {
68
+ if (!this._enabled) {
69
+ return;
70
+ }
71
+ if (feature && typeof feature.name === 'string') {
72
+ const existingIndex = this._features.findIndex((item) => item.name === feature.name);
73
+
74
+ if (existingIndex >= 0) {
75
+ const currentFeature = this._features[existingIndex]!;
76
+ if (currentFeature === feature) {
77
+ return;
78
+ }
79
+
80
+ currentFeature.cleanup?.();
81
+ this._features = this._features.map((item, index) =>
82
+ index === existingIndex ? feature : item,
83
+ );
84
+ } else {
85
+ this._features = [...this._features, feature];
86
+ }
87
+
88
+ feature.setup?.();
89
+ this.updatePanel();
90
+ }
91
+ }
92
+
93
+ removeFeature(name: string): void {
94
+ const idx = this._features.findIndex((f) => f.name === name);
95
+ if (idx >= 0) {
96
+ this._features[idx]!.cleanup?.();
97
+ this._features = this._features.filter((feature) => feature.name !== name);
98
+ this.updatePanel();
99
+ }
100
+ }
101
+
102
+ replaceFeatures(features: DebugFeature[]): void {
103
+ if (!this._enabled) {
104
+ return;
105
+ }
106
+
107
+ const nextFeatures = features.filter(
108
+ (feature, index, array) =>
109
+ feature &&
110
+ typeof feature.name === 'string' &&
111
+ array.findIndex((item) => item.name === feature.name) === index,
112
+ );
113
+ const previousByName = new Map(this._features.map((feature) => [feature.name, feature]));
114
+ const nextByName = new Map(nextFeatures.map((feature) => [feature.name, feature]));
115
+
116
+ this._features.forEach((feature) => {
117
+ const nextFeature = nextByName.get(feature.name);
118
+ if (!nextFeature || nextFeature !== feature) {
119
+ feature.cleanup?.();
120
+ }
121
+ });
122
+
123
+ nextFeatures.forEach((feature) => {
124
+ const currentFeature = previousByName.get(feature.name);
125
+ if (!currentFeature || currentFeature !== feature) {
126
+ feature.setup?.();
127
+ }
128
+ });
129
+
130
+ this._features = nextFeatures;
131
+ this.updatePanel();
132
+ }
133
+
134
+ reset(): void {
135
+ this.hidePanel();
136
+ this._features.forEach((feature) => feature.cleanup?.());
137
+ this._features = [];
138
+ }
139
+
140
+ hasFeatures(): boolean {
141
+ return this._features.length > 0;
142
+ }
143
+
144
+ showPanel(): void {
145
+ if (!this._enabled) {
146
+ return;
147
+ }
148
+ this._panelVisible = true;
149
+ this.updatePanel();
150
+ }
151
+
152
+ hidePanel(): void {
153
+ this._panelVisible = false;
154
+ this.updatePanel();
155
+ }
156
+
157
+ clearAll(): void {
158
+ this._features.forEach((f) => {
159
+ if (f.clear) {
160
+ f.clear();
161
+ } else {
162
+ f.cleanup?.();
163
+ f.setup?.();
164
+ }
165
+ });
166
+ this.updatePanel();
167
+ }
168
+
169
+ destroy(): void {
170
+ this.reset();
171
+ this.unregisterRenderCallback();
172
+ DebugToolkit.instance = null;
173
+ }
174
+ }
@@ -0,0 +1,89 @@
1
+ import React, { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
2
+ import { DebugToolkit } from './DebugToolkit';
3
+ import { FloatPanelView } from '../components/FloatPanelView';
4
+ import type { DebugFeature } from '../types';
5
+
6
+ interface ToolkitContextValue {
7
+ features: DebugFeature[];
8
+ showPanel: () => void;
9
+ hidePanel: () => void;
10
+ addFeature: (feature: DebugFeature) => void;
11
+ removeFeature: (name: string) => void;
12
+ clearAll: () => void;
13
+ destroy: () => void;
14
+ }
15
+
16
+ const ToolkitContext = createContext<ToolkitContextValue | null>(null);
17
+
18
+ interface ProviderState {
19
+ panelVisible: boolean;
20
+ features: DebugFeature[];
21
+ }
22
+
23
+ interface DebugToolkitProviderProps {
24
+ children: ReactNode;
25
+ }
26
+
27
+ export function DebugToolkitProvider({ children }: DebugToolkitProviderProps) {
28
+ const [state, setState] = useState<ProviderState>(() => {
29
+ const toolkit = DebugToolkit.getInstance();
30
+ return {
31
+ panelVisible: toolkit.panelVisible,
32
+ features: toolkit.features,
33
+ };
34
+ });
35
+
36
+ useEffect(() => {
37
+ const toolkit = DebugToolkit.getInstance();
38
+
39
+ const syncState = () => {
40
+ setState({
41
+ panelVisible: toolkit.panelVisible,
42
+ features: toolkit.features,
43
+ });
44
+ };
45
+
46
+ toolkit.registerRenderCallback(syncState);
47
+ syncState();
48
+
49
+ return () => {
50
+ toolkit.unregisterRenderCallback();
51
+ };
52
+ }, []);
53
+
54
+ const toolkit = DebugToolkit.getInstance();
55
+
56
+ const contextValue: ToolkitContextValue = {
57
+ features: state.features,
58
+ showPanel: toolkit.showPanel.bind(toolkit),
59
+ hidePanel: toolkit.hidePanel.bind(toolkit),
60
+ addFeature: toolkit.addFeature.bind(toolkit),
61
+ removeFeature: toolkit.removeFeature.bind(toolkit),
62
+ clearAll: toolkit.clearAll.bind(toolkit),
63
+ destroy: toolkit.destroy.bind(toolkit),
64
+ };
65
+
66
+ return (
67
+ <ToolkitContext.Provider value={contextValue}>
68
+ {children}
69
+ {state.panelVisible && (
70
+ <FloatPanelView
71
+ features={state.features}
72
+ onClose={() => toolkit.hidePanel()}
73
+ onClearAll={() => toolkit.clearAll()}
74
+ />
75
+ )}
76
+ </ToolkitContext.Provider>
77
+ );
78
+ }
79
+
80
+ export function useDebugToolkit(): ToolkitContextValue {
81
+ const context = useContext(ToolkitContext);
82
+ if (!context) {
83
+ throw new Error(
84
+ 'useDebugToolkit must be used within a <DebugToolkitProvider>. ' +
85
+ 'Wrap your app with <DebugToolkitProvider>.',
86
+ );
87
+ }
88
+ return context;
89
+ }
@@ -0,0 +1,11 @@
1
+ import { ClipboardTab } from '../components/ClipboardTab';
2
+ import type { DebugFeature } from '../types';
3
+
4
+ export const createClipboardFeature = (): DebugFeature<void> => ({
5
+ name: 'clipboard',
6
+ label: 'Clipboard',
7
+ renderContent: ClipboardTab,
8
+ setup: () => {},
9
+ getData: () => [],
10
+ cleanup: () => {},
11
+ });
@@ -0,0 +1,118 @@
1
+ import { ConsoleLogTab } from '../components/ConsoleLogTab';
2
+ import type { ConsoleLogEntry, DebugFeature } from '../types';
3
+ import { createEventChannel } from '../utils/createEventChannel';
4
+ import { createObservableStore } from '../utils/createObservableStore';
5
+
6
+ type ConsoleLogPayload = Omit<ConsoleLogEntry, 'id'>;
7
+
8
+ const DEFAULT_MAX_LOGS = 200;
9
+ const consoleChannel = createEventChannel<ConsoleLogPayload>();
10
+ const originalConsole: Partial<Record<ConsoleLogEntry['level'], (...args: unknown[]) => void>> =
11
+ {};
12
+ const LEVELS: ConsoleLogEntry['level'][] = ['log', 'info', 'warn', 'error'];
13
+
14
+ let consoleCaptureRefCount = 0;
15
+
16
+ function stopConsoleCapture(): void {
17
+ consoleCaptureRefCount = Math.max(0, consoleCaptureRefCount - 1);
18
+
19
+ if (consoleCaptureRefCount > 0) {
20
+ return;
21
+ }
22
+
23
+ LEVELS.forEach((level) => {
24
+ const originalMethod = originalConsole[level];
25
+
26
+ if (!originalMethod) {
27
+ return;
28
+ }
29
+
30
+ console[level] = originalMethod;
31
+ delete originalConsole[level];
32
+ });
33
+ }
34
+
35
+ function startConsoleCapture(): () => void {
36
+ consoleCaptureRefCount += 1;
37
+
38
+ if (consoleCaptureRefCount > 1) {
39
+ return () => {
40
+ stopConsoleCapture();
41
+ };
42
+ }
43
+
44
+ LEVELS.forEach((level) => {
45
+ originalConsole[level] = console[level];
46
+
47
+ console[level] = (...args: unknown[]) => {
48
+ originalConsole[level]?.apply(console, args);
49
+ // Skip DebugToolkit's own copy-to-computer logs to avoid Console tab noise
50
+ if (level === 'log' && typeof args[0] === 'string' && args[0].startsWith('[DebugToolkit:Copy]')) {
51
+ return;
52
+ }
53
+ consoleChannel.emit({
54
+ timestamp: Date.now(),
55
+ level,
56
+ data: args,
57
+ });
58
+ };
59
+ });
60
+
61
+ return () => {
62
+ stopConsoleCapture();
63
+ };
64
+ }
65
+
66
+ export interface ConsoleFeatureConfig {
67
+ /** Maximum number of console logs to keep (default: 200) */
68
+ maxLogs?: number;
69
+ }
70
+
71
+ export const createConsoleLogFeature = (config?: ConsoleFeatureConfig): DebugFeature<ConsoleLogEntry> => {
72
+ const maxLogs = config?.maxLogs ?? DEFAULT_MAX_LOGS;
73
+ const logStore = createObservableStore<ConsoleLogEntry>();
74
+ let nextId = 0;
75
+ let initialized = false;
76
+ let unsubscribeLogs: (() => void) | null = null;
77
+ let stopCapture: (() => void) | null = null;
78
+
79
+ return {
80
+ name: 'console',
81
+ label: 'Console',
82
+ renderContent: ConsoleLogTab,
83
+ setup: () => {
84
+ if (initialized) {
85
+ return;
86
+ }
87
+
88
+ unsubscribeLogs = consoleChannel.subscribe((entry) => {
89
+ logStore.push(
90
+ {
91
+ ...entry,
92
+ id: String(nextId++),
93
+ },
94
+ maxLogs,
95
+ );
96
+ });
97
+ stopCapture = startConsoleCapture();
98
+ initialized = true;
99
+ },
100
+ getData: () => logStore.getData(),
101
+ clear: () => {
102
+ logStore.clear();
103
+ },
104
+ cleanup: () => {
105
+ if (!initialized) {
106
+ return;
107
+ }
108
+
109
+ unsubscribeLogs?.();
110
+ unsubscribeLogs = null;
111
+ stopCapture?.();
112
+ stopCapture = null;
113
+ logStore.clear();
114
+ initialized = false;
115
+ },
116
+ subscribe: (listener) => logStore.subscribe(listener),
117
+ };
118
+ };
@@ -0,0 +1,194 @@
1
+ import { EnvironmentTab } from '../components/EnvironmentTab';
2
+ import type { DebugFeature, EnvironmentConfig, EnvironmentState } from '../types';
3
+ import { createObservableStore } from '../utils/createObservableStore';
4
+ import { setUrlRewriter } from './NetworkFeature';
5
+
6
+ // Lazy AsyncStorage loader
7
+ type AsyncStorageModule = {
8
+ getItem: (key: string) => Promise<string | null>;
9
+ setItem: (key: string, value: string) => Promise<void>;
10
+ };
11
+
12
+ let asyncStorageModule: AsyncStorageModule | null = null;
13
+ let asyncStorageChecked = false;
14
+
15
+ function getAsyncStorage(): AsyncStorageModule | null {
16
+ if (asyncStorageChecked) {
17
+ return asyncStorageModule;
18
+ }
19
+ asyncStorageChecked = true;
20
+ try {
21
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
22
+ asyncStorageModule = require('@react-native-async-storage/async-storage').default;
23
+ } catch {
24
+ asyncStorageModule = null;
25
+ }
26
+ return asyncStorageModule;
27
+ }
28
+
29
+ const STORAGE_KEY = 'debug_toolkit_env_id';
30
+
31
+ // Module-level state for synchronous URL rewriting
32
+ let currentHostsMap: Map<string, string> | null = null;
33
+ let activeEnvironmentId: string | null = null;
34
+
35
+ function buildHostsMap(
36
+ environments: EnvironmentConfig[],
37
+ targetId: string | null,
38
+ ): Map<string, string> | null {
39
+ if (!targetId) return null;
40
+ const target = environments.find((e) => e.id === targetId);
41
+ if (!target) return null;
42
+
43
+ const map = new Map<string, string>();
44
+ for (const env of environments) {
45
+ if (env.id !== targetId) {
46
+ map.set(env.host, target.host);
47
+ }
48
+ }
49
+ return map;
50
+ }
51
+
52
+ function createUrlRewriter(): (url: string) => string {
53
+ return (url: string): string => {
54
+ if (!currentHostsMap) return url;
55
+
56
+ try {
57
+ const parsed = new URL(url);
58
+ const targetHost = currentHostsMap.get(parsed.host);
59
+ if (targetHost) {
60
+ return url.replace(parsed.host, targetHost);
61
+ }
62
+ } catch {
63
+ // Not a valid URL or relative URL — return unchanged
64
+ }
65
+
66
+ return url;
67
+ };
68
+ }
69
+
70
+ export interface EnvironmentFeatureAPI extends DebugFeature<EnvironmentState> {
71
+ registerEnvironments: (environments: EnvironmentConfig[]) => void;
72
+ switchEnvironment: (environmentId: string | null) => void;
73
+ getCurrentEnvironmentId: () => string | null;
74
+ }
75
+
76
+ export const createEnvironmentFeature = (
77
+ initialEnvironments?: EnvironmentConfig[],
78
+ ): EnvironmentFeatureAPI => {
79
+ const stateStore = createObservableStore<EnvironmentState>();
80
+ let environments: EnvironmentConfig[] = initialEnvironments ?? [];
81
+ let initialized = false;
82
+
83
+ const getCurrentState = (): EnvironmentState => ({
84
+ environments,
85
+ currentEnvironmentId: activeEnvironmentId,
86
+ });
87
+
88
+ const updateStore = () => {
89
+ stateStore.clear();
90
+ stateStore.push(getCurrentState());
91
+ };
92
+
93
+ const applyEnvironment = (envId: string | null) => {
94
+ activeEnvironmentId = envId;
95
+ currentHostsMap = buildHostsMap(environments, envId);
96
+
97
+ if (initialized) {
98
+ try {
99
+ if (envId && environments.length > 0) {
100
+ setUrlRewriter(createUrlRewriter());
101
+ } else {
102
+ setUrlRewriter(null);
103
+ }
104
+ } catch (err) {
105
+ if (__DEV__) console.warn('[DebugToolkit] Failed to set URL rewriter:', err);
106
+ }
107
+ }
108
+
109
+ updateStore();
110
+ };
111
+
112
+ const persistSelection = async (envId: string | null) => {
113
+ const storage = getAsyncStorage();
114
+ if (!storage) return;
115
+ try {
116
+ await storage.setItem(STORAGE_KEY, envId ?? '');
117
+ } catch (err) {
118
+ if (__DEV__) console.warn('[DebugToolkit] Failed to persist environment selection:', err);
119
+ }
120
+ };
121
+
122
+ const loadPersistedSelection = async () => {
123
+ const storage = getAsyncStorage();
124
+ if (!storage) return;
125
+ try {
126
+ const stored = await storage.getItem(STORAGE_KEY);
127
+ if (stored && stored !== '' && environments.some((e) => e.id === stored)) {
128
+ applyEnvironment(stored);
129
+ }
130
+ } catch (err) {
131
+ if (__DEV__) console.warn('[DebugToolkit] Failed to load persisted environment:', err);
132
+ }
133
+ };
134
+
135
+ return {
136
+ name: 'environment',
137
+ label: 'Environment',
138
+ renderContent: EnvironmentTab,
139
+ setup: () => {
140
+ if (initialized) return;
141
+
142
+ updateStore();
143
+ initialized = true;
144
+
145
+ // Install rewriter if an environment is already selected
146
+ if (activeEnvironmentId && environments.length > 0) {
147
+ try {
148
+ setUrlRewriter(createUrlRewriter());
149
+ } catch {
150
+ // NetworkFeature may not be available
151
+ }
152
+ }
153
+
154
+ // Async persistence load (will override if a preference exists)
155
+ loadPersistedSelection();
156
+ },
157
+ getData: () => stateStore.getData(),
158
+ clear: () => {
159
+ applyEnvironment(null);
160
+ persistSelection(null);
161
+ },
162
+ cleanup: () => {
163
+ if (!initialized) return;
164
+ try {
165
+ setUrlRewriter(null);
166
+ } catch (err) {
167
+ if (__DEV__) console.warn('[DebugToolkit] Failed to set URL rewriter:', err);
168
+ }
169
+ activeEnvironmentId = null;
170
+ currentHostsMap = null;
171
+ stateStore.clear();
172
+ initialized = false;
173
+ },
174
+ subscribe: (listener) => stateStore.subscribe(listener),
175
+ registerEnvironments: (envs: EnvironmentConfig[]) => {
176
+ environments = envs;
177
+ applyEnvironment(activeEnvironmentId);
178
+ },
179
+ switchEnvironment: (envId: string | null) => {
180
+ applyEnvironment(envId);
181
+ persistSelection(envId);
182
+ },
183
+ getCurrentEnvironmentId: () => activeEnvironmentId,
184
+ badge: () => {
185
+ if (!activeEnvironmentId) return null;
186
+ const env = environments.find((e) => e.id === activeEnvironmentId);
187
+ if (!env) return null;
188
+ return {
189
+ label: env.label.substring(0, 3).toUpperCase(),
190
+ color: env.color ?? '#FF9500',
191
+ };
192
+ },
193
+ };
194
+ };