react-native-inapp-inspector 2.3.18 → 2.3.20
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/android/src/main/java/com/inappinspector/NetworkInspectorModule.kt +57 -0
- package/dist/commonjs/analytics.js +1 -24
- package/dist/commonjs/bundle.js +1 -16
- package/dist/commonjs/capture.d.ts +2 -0
- package/dist/commonjs/capture.js +1 -32
- package/dist/commonjs/components/AnalyticsDetail.js +92 -623
- package/dist/commonjs/components/AnalyticsEventCard.js +54 -350
- package/dist/commonjs/components/AnalyticsGraph.js +70 -370
- package/dist/commonjs/components/AnimatedEntrance.js +1 -11
- package/dist/commonjs/components/AppHeaderLogo.js +7 -134
- package/dist/commonjs/components/BrandCircleIcon.js +73 -118
- package/dist/commonjs/components/BrandSquareIcon.js +63 -108
- package/dist/commonjs/components/CodeSnippet.js +48 -623
- package/dist/commonjs/components/ConsoleLogCard.js +63 -537
- package/dist/commonjs/components/CopyButton.js +3 -89
- package/dist/commonjs/components/DiffViewer.js +19 -83
- package/dist/commonjs/components/DomainHeader.js +27 -127
- package/dist/commonjs/components/EmptyState.d.ts +1 -0
- package/dist/commonjs/components/EmptyState.js +10 -87
- package/dist/commonjs/components/EndOfListFooter.js +7 -81
- package/dist/commonjs/components/ErrorBoundary.js +72 -566
- package/dist/commonjs/components/HeadersSection.js +31 -110
- package/dist/commonjs/components/HighlightText.js +17 -58
- package/dist/commonjs/components/Inspector/AboutModal.d.ts +6 -0
- package/dist/commonjs/components/Inspector/AboutModal.js +351 -0
- package/dist/commonjs/components/Inspector/AnalyticsFilterModal.js +98 -797
- package/dist/commonjs/components/Inspector/AnalyticsTab.js +284 -930
- package/dist/commonjs/components/Inspector/BundleTab.js +551 -2918
- package/dist/commonjs/components/Inspector/ConsoleTab.js +79 -492
- package/dist/commonjs/components/Inspector/CrashDetail.js +123 -672
- package/dist/commonjs/components/Inspector/CrashFilterModal.js +66 -498
- package/dist/commonjs/components/Inspector/CrashTab.js +98 -670
- package/dist/commonjs/components/Inspector/DebuggingTab.js +64 -871
- package/dist/commonjs/components/Inspector/DeviceInfoTab.js +143 -907
- package/dist/commonjs/components/Inspector/FabLauncher.js +85 -54
- package/dist/commonjs/components/Inspector/FeatureUnderDevNotice.js +6 -99
- package/dist/commonjs/components/Inspector/FeedbackModal.d.ts +9 -0
- package/dist/commonjs/components/Inspector/FeedbackModal.js +167 -521
- package/dist/commonjs/components/Inspector/InspectorContext.js +1 -21
- package/dist/commonjs/components/Inspector/InspectorHeader.js +219 -1093
- package/dist/commonjs/components/Inspector/LogDetail.js +168 -994
- package/dist/commonjs/components/Inspector/MainScreen.js +60 -332
- package/dist/commonjs/components/Inspector/MediaGalleryTab.js +136 -278
- package/dist/commonjs/components/Inspector/MediaPreviewModal.js +134 -361
- package/dist/commonjs/components/Inspector/NavigationTracker.js +1 -12
- package/dist/commonjs/components/Inspector/NetworkDetail.js +96 -432
- package/dist/commonjs/components/Inspector/NetworkFilterModal.js +60 -576
- package/dist/commonjs/components/Inspector/NetworkTab.js +84 -514
- package/dist/commonjs/components/Inspector/NpmStarPrompt.js +17 -433
- package/dist/commonjs/components/Inspector/NpmUpdateToast.js +25 -298
- package/dist/commonjs/components/Inspector/PerformanceTab.js +182 -1397
- package/dist/commonjs/components/Inspector/ReduxDetail.js +188 -1089
- package/dist/commonjs/components/Inspector/ReduxTab.js +85 -701
- package/dist/commonjs/components/Inspector/SettingsPanel.js +431 -3431
- package/dist/commonjs/components/Inspector/SkeletonPlaceholder.js +11 -180
- package/dist/commonjs/components/Inspector/StorageTab.js +93 -826
- package/dist/commonjs/components/Inspector/TabBar.js +47 -183
- package/dist/commonjs/components/Inspector/UpdateAvailableModal.js +34 -408
- package/dist/commonjs/components/JsonViewer.js +168 -380
- package/dist/commonjs/components/LogCard.js +57 -567
- package/dist/commonjs/components/LogSyntaxHighlighter.js +11 -130
- package/dist/commonjs/components/MetaAccordion.js +69 -238
- package/dist/commonjs/components/MiniBarChart.js +3 -56
- package/dist/commonjs/components/MiniLineChart.js +3 -58
- package/dist/commonjs/components/NetworkIcons.d.ts +7 -0
- package/dist/commonjs/components/NetworkIcons.js +479 -997
- package/dist/commonjs/components/QRCodeView.js +5 -79
- package/dist/commonjs/components/SectionHeader.js +15 -37
- package/dist/commonjs/components/SegmentedTabs.js +7 -61
- package/dist/commonjs/components/SkeletonPlaceholder.js +11 -180
- package/dist/commonjs/components/Slider.js +15 -243
- package/dist/commonjs/components/SourcePageCard.js +30 -89
- package/dist/commonjs/components/Toast.js +5 -147
- package/dist/commonjs/components/TouchableScale.js +3 -24
- package/dist/commonjs/components/TreeNode.js +55 -130
- package/dist/commonjs/console.js +1 -16
- package/dist/commonjs/constants/index.js +1 -32
- package/dist/commonjs/constants/telemetryConfig.js +1 -6
- package/dist/commonjs/constants/version.d.ts +1 -1
- package/dist/commonjs/constants/version.js +1 -4
- package/dist/commonjs/crash.js +1 -23
- package/dist/commonjs/customHooks/analyticsLogger.js +1 -250
- package/dist/commonjs/customHooks/bundleAnalyzer.js +1 -957
- package/dist/commonjs/customHooks/consoleLogger.js +6 -445
- package/dist/commonjs/customHooks/crashHandler.js +7 -656
- package/dist/commonjs/customHooks/logFilters.js +1 -23
- package/dist/commonjs/customHooks/networkLogger.js +2 -536
- package/dist/commonjs/customHooks/performanceTracker.js +63 -750
- package/dist/commonjs/customHooks/reduxLogger.js +2 -313
- package/dist/commonjs/customHooks/storageInspector.js +1 -435
- package/dist/commonjs/customHooks/useAccordion.js +1 -18
- package/dist/commonjs/decorators/index.js +1 -100
- package/dist/commonjs/helpers/gaAnalyticsRegistry.js +1 -148
- package/dist/commonjs/helpers/index.js +8 -921
- package/dist/commonjs/helpers/memoryManager.js +1 -99
- package/dist/commonjs/helpers/qrGenerator.js +1 -367
- package/dist/commonjs/helpers/remoteConfig.js +1 -165
- package/dist/commonjs/helpers/searchQueryParser.js +1 -62
- package/dist/commonjs/helpers/settingsStore.js +1 -144
- package/dist/commonjs/helpers/telemetry.js +1 -501
- package/dist/commonjs/helpers/toast.js +1 -20
- package/dist/commonjs/i18n/index.js +1 -90
- package/dist/commonjs/i18n/locales/en.json +1 -1122
- package/dist/commonjs/index.js +5 -2153
- package/dist/commonjs/metro.js +6 -468
- package/dist/commonjs/native/NativeInspector.d.ts +3 -0
- package/dist/commonjs/native/NativeInspector.js +1 -402
- package/dist/commonjs/native/NativeNetworkInspector.d.ts +1 -0
- package/dist/commonjs/native/NativeNetworkInspector.js +1 -4
- package/dist/commonjs/network.js +1 -13
- package/dist/commonjs/performance.js +1 -29
- package/dist/commonjs/redux.js +1 -20
- package/dist/commonjs/storage.js +1 -14
- package/dist/commonjs/styles/AppColors.js +1 -423
- package/dist/commonjs/styles/AppFonts.js +1 -17
- package/dist/commonjs/styles/common.js +1 -190
- package/dist/commonjs/styles/index.d.ts +6 -0
- package/dist/commonjs/styles/index.js +1 -1589
- package/dist/commonjs/types/enums.d.ts +2 -1
- package/dist/commonjs/types/enums.js +1 -150
- package/dist/commonjs/types/index.js +1 -18
- package/dist/commonjs/types/interfaces.d.ts +7 -0
- package/dist/commonjs/types/interfaces.js +1 -2
- package/dist/esm/analytics.js +1 -2
- package/dist/esm/bundle.js +1 -2
- package/dist/esm/capture.d.ts +2 -0
- package/dist/esm/capture.js +1 -29
- package/dist/esm/components/AnalyticsDetail.js +171 -664
- package/dist/esm/components/AnalyticsEventCard.js +77 -335
- package/dist/esm/components/AnalyticsGraph.js +95 -357
- package/dist/esm/components/AnimatedEntrance.js +1 -6
- package/dist/esm/components/AppHeaderLogo.js +7 -94
- package/dist/esm/components/BrandCircleIcon.js +114 -119
- package/dist/esm/components/BrandSquareIcon.js +73 -78
- package/dist/esm/components/CodeSnippet.js +58 -595
- package/dist/esm/components/ConsoleLogCard.js +91 -526
- package/dist/esm/components/CopyButton.js +3 -51
- package/dist/esm/components/DiffViewer.js +22 -48
- package/dist/esm/components/DomainHeader.js +43 -138
- package/dist/esm/components/EmptyState.d.ts +1 -0
- package/dist/esm/components/EmptyState.js +17 -56
- package/dist/esm/components/EndOfListFooter.js +15 -83
- package/dist/esm/components/ErrorBoundary.js +125 -582
- package/dist/esm/components/HeadersSection.js +52 -93
- package/dist/esm/components/HighlightText.js +17 -53
- package/dist/esm/components/Inspector/AboutModal.d.ts +6 -0
- package/dist/esm/components/Inspector/AboutModal.js +351 -0
- package/dist/esm/components/Inspector/AnalyticsFilterModal.js +225 -886
- package/dist/esm/components/Inspector/AnalyticsTab.js +296 -904
- package/dist/esm/components/Inspector/BundleTab.js +1175 -3502
- package/dist/esm/components/Inspector/ConsoleTab.js +113 -488
- package/dist/esm/components/Inspector/CrashDetail.js +236 -747
- package/dist/esm/components/Inspector/CrashFilterModal.js +149 -541
- package/dist/esm/components/Inspector/CrashTab.js +177 -711
- package/dist/esm/components/Inspector/DebuggingTab.js +156 -923
- package/dist/esm/components/Inspector/DeviceInfoTab.js +199 -924
- package/dist/esm/components/Inspector/FabLauncher.js +85 -49
- package/dist/esm/components/Inspector/FeatureUnderDevNotice.js +14 -70
- package/dist/esm/components/Inspector/FeedbackModal.d.ts +9 -0
- package/dist/esm/components/Inspector/FeedbackModal.js +182 -499
- package/dist/esm/components/Inspector/InspectorContext.js +1 -12
- package/dist/esm/components/Inspector/InspectorHeader.js +309 -1145
- package/dist/esm/components/Inspector/LogDetail.js +235 -1023
- package/dist/esm/components/Inspector/MainScreen.js +86 -320
- package/dist/esm/components/Inspector/MediaGalleryTab.js +157 -259
- package/dist/esm/components/Inspector/MediaPreviewModal.js +153 -340
- package/dist/esm/components/Inspector/NavigationTracker.js +1 -10
- package/dist/esm/components/Inspector/NetworkDetail.js +141 -472
- package/dist/esm/components/Inspector/NetworkFilterModal.js +122 -597
- package/dist/esm/components/Inspector/NetworkTab.js +125 -517
- package/dist/esm/components/Inspector/NpmStarPrompt.js +58 -434
- package/dist/esm/components/Inspector/NpmUpdateToast.js +45 -281
- package/dist/esm/components/Inspector/PerformanceTab.js +393 -1570
- package/dist/esm/components/Inspector/ReduxDetail.js +307 -1170
- package/dist/esm/components/Inspector/ReduxTab.js +144 -722
- package/dist/esm/components/Inspector/SettingsPanel.js +647 -3609
- package/dist/esm/components/Inspector/SkeletonPlaceholder.js +30 -163
- package/dist/esm/components/Inspector/StorageTab.js +172 -866
- package/dist/esm/components/Inspector/TabBar.js +52 -183
- package/dist/esm/components/Inspector/UpdateAvailableModal.js +79 -416
- package/dist/esm/components/JsonViewer.js +179 -353
- package/dist/esm/components/LogCard.js +93 -565
- package/dist/esm/components/LogSyntaxHighlighter.js +11 -123
- package/dist/esm/components/MetaAccordion.js +136 -267
- package/dist/esm/components/MiniBarChart.js +3 -18
- package/dist/esm/components/MiniLineChart.js +3 -20
- package/dist/esm/components/NetworkIcons.d.ts +7 -0
- package/dist/esm/components/NetworkIcons.js +481 -817
- package/dist/esm/components/QRCodeView.js +8 -45
- package/dist/esm/components/SectionHeader.js +22 -39
- package/dist/esm/components/SegmentedTabs.js +8 -57
- package/dist/esm/components/SkeletonPlaceholder.js +30 -163
- package/dist/esm/components/Slider.js +24 -213
- package/dist/esm/components/SourcePageCard.js +65 -86
- package/dist/esm/components/Toast.js +10 -117
- package/dist/esm/components/TouchableScale.js +3 -19
- package/dist/esm/components/TreeNode.js +58 -95
- package/dist/esm/console.js +1 -2
- package/dist/esm/constants/index.js +1 -28
- package/dist/esm/constants/telemetryConfig.js +1 -3
- package/dist/esm/constants/version.d.ts +1 -1
- package/dist/esm/constants/version.js +1 -1
- package/dist/esm/crash.js +1 -2
- package/dist/esm/customHooks/analyticsLogger.js +1 -230
- package/dist/esm/customHooks/bundleAnalyzer.js +1 -944
- package/dist/esm/customHooks/consoleLogger.js +6 -432
- package/dist/esm/customHooks/crashHandler.js +7 -630
- package/dist/esm/customHooks/logFilters.js +1 -20
- package/dist/esm/customHooks/networkLogger.js +2 -519
- package/dist/esm/customHooks/performanceTracker.js +63 -723
- package/dist/esm/customHooks/reduxLogger.js +2 -293
- package/dist/esm/customHooks/storageInspector.js +1 -418
- package/dist/esm/customHooks/useAccordion.js +1 -16
- package/dist/esm/decorators/index.js +1 -95
- package/dist/esm/helpers/gaAnalyticsRegistry.js +1 -143
- package/dist/esm/helpers/index.js +8 -861
- package/dist/esm/helpers/memoryManager.js +1 -91
- package/dist/esm/helpers/qrGenerator.js +1 -364
- package/dist/esm/helpers/remoteConfig.js +1 -160
- package/dist/esm/helpers/searchQueryParser.js +1 -59
- package/dist/esm/helpers/settingsStore.js +1 -134
- package/dist/esm/helpers/telemetry.js +1 -489
- package/dist/esm/helpers/toast.js +1 -15
- package/dist/esm/i18n/index.js +1 -78
- package/dist/esm/i18n/locales/en.json +1 -1122
- package/dist/esm/index.js +7 -1967
- package/dist/esm/metro.js +6 -459
- package/dist/esm/native/NativeInspector.d.ts +3 -0
- package/dist/esm/native/NativeInspector.js +1 -370
- package/dist/esm/native/NativeNetworkInspector.d.ts +1 -0
- package/dist/esm/native/NativeNetworkInspector.js +1 -2
- package/dist/esm/network.js +1 -1
- package/dist/esm/performance.js +1 -2
- package/dist/esm/redux.js +1 -1
- package/dist/esm/storage.js +1 -1
- package/dist/esm/styles/AppColors.js +1 -417
- package/dist/esm/styles/AppFonts.js +1 -13
- package/dist/esm/styles/common.js +1 -186
- package/dist/esm/styles/index.d.ts +6 -0
- package/dist/esm/styles/index.js +1 -1551
- package/dist/esm/types/enums.d.ts +2 -1
- package/dist/esm/types/enums.js +1 -147
- package/dist/esm/types/index.js +1 -2
- package/dist/esm/types/interfaces.d.ts +7 -0
- package/dist/esm/types/interfaces.js +1 -1
- package/ios/NetworkInspectorModule.mm +253 -136
- package/package.json +5 -3
- package/react-native-inapp-inspector.podspec +1 -1
- package/src/native/NativeInspector.ts +17 -0
- package/src/native/NativeNetworkInspector.ts +1 -0
- package/src/analytics.ts +0 -35
- package/src/bundle.ts +0 -25
- package/src/capture.ts +0 -101
- package/src/components/AnalyticsDetail.tsx +0 -870
- package/src/components/AnalyticsEventCard.tsx +0 -444
- package/src/components/AnalyticsGraph.tsx +0 -583
- package/src/components/AnimatedEntrance.tsx +0 -20
- package/src/components/AppHeaderLogo.tsx +0 -143
- package/src/components/BrandCircleIcon.tsx +0 -144
- package/src/components/BrandSquareIcon.tsx +0 -184
- package/src/components/CodeSnippet.tsx +0 -725
- package/src/components/ConsoleLogCard.tsx +0 -679
- package/src/components/CopyButton.tsx +0 -87
- package/src/components/DiffViewer.tsx +0 -82
- package/src/components/DomainHeader.tsx +0 -224
- package/src/components/EmptyState.tsx +0 -95
- package/src/components/EndOfListFooter.tsx +0 -100
- package/src/components/ErrorBoundary.tsx +0 -688
- package/src/components/HeadersSection.tsx +0 -172
- package/src/components/HighlightText.tsx +0 -100
- package/src/components/Inspector/AnalyticsFilterModal.tsx +0 -1250
- package/src/components/Inspector/AnalyticsTab.tsx +0 -1362
- package/src/components/Inspector/BundleTab.tsx +0 -4768
- package/src/components/Inspector/ConsoleTab.tsx +0 -726
- package/src/components/Inspector/CrashDetail.tsx +0 -997
- package/src/components/Inspector/CrashFilterModal.tsx +0 -721
- package/src/components/Inspector/CrashTab.tsx +0 -933
- package/src/components/Inspector/DebuggingTab.tsx +0 -1103
- package/src/components/Inspector/DeviceInfoTab.tsx +0 -1397
- package/src/components/Inspector/FabLauncher.tsx +0 -80
- package/src/components/Inspector/FeatureUnderDevNotice.tsx +0 -94
- package/src/components/Inspector/FeedbackModal.tsx +0 -626
- package/src/components/Inspector/InspectorContext.tsx +0 -28
- package/src/components/Inspector/InspectorHeader.tsx +0 -1545
- package/src/components/Inspector/LogDetail.tsx +0 -1431
- package/src/components/Inspector/MainScreen.tsx +0 -459
- package/src/components/Inspector/MediaGalleryTab.tsx +0 -355
- package/src/components/Inspector/MediaPreviewModal.tsx +0 -435
- package/src/components/Inspector/NavigationTracker.tsx +0 -13
- package/src/components/Inspector/NetworkDetail.tsx +0 -795
- package/src/components/Inspector/NetworkFilterModal.tsx +0 -730
- package/src/components/Inspector/NetworkTab.tsx +0 -820
- package/src/components/Inspector/NpmStarPrompt.tsx +0 -532
- package/src/components/Inspector/NpmUpdateToast.tsx +0 -387
- package/src/components/Inspector/PerformanceTab.tsx +0 -1967
- package/src/components/Inspector/ReduxDetail.tsx +0 -1651
- package/src/components/Inspector/ReduxTab.tsx +0 -987
- package/src/components/Inspector/SettingsPanel.tsx +0 -4580
- package/src/components/Inspector/SkeletonPlaceholder.tsx +0 -206
- package/src/components/Inspector/StorageTab.tsx +0 -1159
- package/src/components/Inspector/TabBar.tsx +0 -263
- package/src/components/Inspector/UpdateAvailableModal.tsx +0 -555
- package/src/components/JsonViewer.tsx +0 -547
- package/src/components/LogCard.tsx +0 -694
- package/src/components/LogSyntaxHighlighter.tsx +0 -178
- package/src/components/MetaAccordion.tsx +0 -355
- package/src/components/MiniBarChart.tsx +0 -42
- package/src/components/MiniLineChart.tsx +0 -33
- package/src/components/NetworkIcons.tsx +0 -2599
- package/src/components/QRCodeView.tsx +0 -75
- package/src/components/SectionHeader.tsx +0 -101
- package/src/components/SegmentedTabs.tsx +0 -83
- package/src/components/SkeletonPlaceholder.tsx +0 -206
- package/src/components/Slider.tsx +0 -300
- package/src/components/SourcePageCard.tsx +0 -150
- package/src/components/Toast.tsx +0 -131
- package/src/components/TouchableScale.tsx +0 -61
- package/src/components/TreeNode.tsx +0 -171
- package/src/console.ts +0 -24
- package/src/constants/index.ts +0 -41
- package/src/constants/telemetryConfig.ts +0 -4
- package/src/constants/version.ts +0 -3
- package/src/crash.ts +0 -32
- package/src/customHooks/analyticsLogger.ts +0 -336
- package/src/customHooks/bundleAnalyzer.ts +0 -1256
- package/src/customHooks/consoleLogger.ts +0 -530
- package/src/customHooks/crashHandler.ts +0 -944
- package/src/customHooks/logFilters.ts +0 -32
- package/src/customHooks/networkLogger.ts +0 -624
- package/src/customHooks/performanceTracker.ts +0 -1014
- package/src/customHooks/reduxLogger.ts +0 -406
- package/src/customHooks/storageInspector.ts +0 -513
- package/src/customHooks/useAccordion.tsx +0 -27
- package/src/decorators/index.ts +0 -184
- package/src/helpers/gaAnalyticsRegistry.ts +0 -204
- package/src/helpers/index.ts +0 -1092
- package/src/helpers/memoryManager.ts +0 -138
- package/src/helpers/qrGenerator.ts +0 -430
- package/src/helpers/remoteConfig.ts +0 -212
- package/src/helpers/searchQueryParser.ts +0 -84
- package/src/helpers/settingsStore.ts +0 -171
- package/src/helpers/telemetry.ts +0 -568
- package/src/helpers/toast.ts +0 -17
- package/src/i18n/index.ts +0 -104
- package/src/i18n/locales/en.json +0 -1125
- package/src/index.tsx +0 -2635
- package/src/metro.ts +0 -598
- package/src/network.ts +0 -22
- package/src/performance.ts +0 -38
- package/src/redux.ts +0 -23
- package/src/storage.ts +0 -18
- package/src/styles/AppColors.ts +0 -455
- package/src/styles/AppFonts.ts +0 -26
- package/src/styles/common.ts +0 -209
- package/src/styles/index.ts +0 -1606
- package/src/types/enums.ts +0 -208
- package/src/types/index.ts +0 -34
- package/src/types/interfaces.ts +0 -530
|
@@ -1,725 +0,0 @@
|
|
|
1
|
-
import React, {useMemo, useState, useRef, useEffect} from 'react';
|
|
2
|
-
import {StyleSheet, Text, View, Platform, FlatList, TextInput, Pressable} from 'react-native';
|
|
3
|
-
import Svg, {Path} from 'react-native-svg';
|
|
4
|
-
import {SearchIcon, ClearIcon} from './NetworkIcons';
|
|
5
|
-
import CopyButton from './CopyButton';
|
|
6
|
-
import TouchableScale from './TouchableScale';
|
|
7
|
-
import {AppColors} from '../styles/AppColors';
|
|
8
|
-
import {AppFonts} from '../styles/AppFonts';
|
|
9
|
-
import {CodeSnippetProps} from '../types';
|
|
10
|
-
|
|
11
|
-
const escapeRegExp = (string: string) => {
|
|
12
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// HTML pretty printer
|
|
16
|
-
const formatHTML = (html: string): string => {
|
|
17
|
-
if (!html) return '';
|
|
18
|
-
let indent = 0;
|
|
19
|
-
const cleaned = html
|
|
20
|
-
.replace(/<([a-zA-Z0-9:-]+)([^>]*)>\s*<\/([a-zA-Z0-9:-]+)>/g, '<$1$2></$3>')
|
|
21
|
-
.replace(/(<[^>]+>)/g, '\n$1\n')
|
|
22
|
-
.replace(/\n+/g, '\n');
|
|
23
|
-
|
|
24
|
-
const lines = cleaned.split('\n');
|
|
25
|
-
const formatted: string[] = [];
|
|
26
|
-
const selfClosingTags =
|
|
27
|
-
/^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/i;
|
|
28
|
-
|
|
29
|
-
for (let i = 0; i < lines.length; i++) {
|
|
30
|
-
const line = lines[i].trim();
|
|
31
|
-
if (!line) continue;
|
|
32
|
-
|
|
33
|
-
if (line.startsWith('</')) {
|
|
34
|
-
indent = Math.max(0, indent - 1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
formatted.push(' '.repeat(indent) + line);
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
line.startsWith('<') &&
|
|
41
|
-
!line.startsWith('</') &&
|
|
42
|
-
!line.startsWith('<!') &&
|
|
43
|
-
!line.endsWith('/>')
|
|
44
|
-
) {
|
|
45
|
-
const tagNameMatch = line.match(/^<([a-zA-Z0-9:-]+)/);
|
|
46
|
-
if (tagNameMatch) {
|
|
47
|
-
const tagName = tagNameMatch[1];
|
|
48
|
-
if (!selfClosingTags.test(tagName)) {
|
|
49
|
-
const closeTagRegex = new RegExp(`</${escapeRegExp(tagName)}>`);
|
|
50
|
-
if (!closeTagRegex.test(line)) {
|
|
51
|
-
indent++;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return formatted.join('\n');
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// CSS pretty printer
|
|
61
|
-
const formatCSS = (css: string): string => {
|
|
62
|
-
if (!css) return '';
|
|
63
|
-
const cleaned = css
|
|
64
|
-
.replace(/\s*\{\s*/g, ' {\n')
|
|
65
|
-
.replace(/\s*;\s*/g, ';\n')
|
|
66
|
-
.replace(/\s*\}\s*/g, '\n}\n')
|
|
67
|
-
.replace(/\n+/g, '\n');
|
|
68
|
-
|
|
69
|
-
const lines = cleaned.split('\n');
|
|
70
|
-
let indent = 0;
|
|
71
|
-
const formatted: string[] = [];
|
|
72
|
-
|
|
73
|
-
for (let i = 0; i < lines.length; i++) {
|
|
74
|
-
const line = lines[i].trim();
|
|
75
|
-
if (!line) continue;
|
|
76
|
-
|
|
77
|
-
if (line.startsWith('}')) {
|
|
78
|
-
indent = Math.max(0, indent - 1);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
formatted.push(' '.repeat(indent) + line);
|
|
82
|
-
|
|
83
|
-
if (line.endsWith('{')) {
|
|
84
|
-
indent++;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return formatted.join('\n');
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// JS pretty printer
|
|
91
|
-
const formatJS = (js: string): string => {
|
|
92
|
-
if (!js) return '';
|
|
93
|
-
const lines = js.split(/\r?\n/);
|
|
94
|
-
let indent = 0;
|
|
95
|
-
const formatted: string[] = [];
|
|
96
|
-
|
|
97
|
-
for (let i = 0; i < lines.length; i++) {
|
|
98
|
-
const line = lines[i].trim();
|
|
99
|
-
if (!line) continue;
|
|
100
|
-
|
|
101
|
-
let openCount = (line.match(/\{|\[/g) || []).length;
|
|
102
|
-
let closeCount = (line.match(/\}|\]/g) || []).length;
|
|
103
|
-
|
|
104
|
-
if (line.startsWith('}') || line.startsWith(']')) {
|
|
105
|
-
indent = Math.max(0, indent - 1);
|
|
106
|
-
} else if (closeCount > openCount) {
|
|
107
|
-
indent = Math.max(0, indent - (closeCount - openCount));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
formatted.push(' '.repeat(indent) + line);
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
openCount > closeCount &&
|
|
114
|
-
!line.startsWith('}') &&
|
|
115
|
-
!line.startsWith(']')
|
|
116
|
-
) {
|
|
117
|
-
indent += openCount - closeCount;
|
|
118
|
-
} else if (line.endsWith('{') || line.endsWith('[')) {
|
|
119
|
-
indent++;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return formatted.join('\n');
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const tokenizeJS = (text: string) => {
|
|
126
|
-
const tokens: {text: string; type: string}[] = [];
|
|
127
|
-
const regex =
|
|
128
|
-
/(\/\/.*|\/\*[\s\S]*?\*\/)|(\"(?:\\.|[^\"\\])*\"|\'(?:\\.|[^\'\\])*\'|\`(?:\\.|[^\`\\])*\`)|(\b(const|let|var|function|return|if|else|for|while|import|export|class|try|catch|new|this|async|await|break|continue|switch|case|default|throw|typeof|yield)\b)|(\b(console|window|document|fetch|global|require|module|exports|Promise|Map|Set|Array|Object|String|Number|Boolean)\b)|(\b\d+(?:\.\d+)?\b)/g;
|
|
129
|
-
|
|
130
|
-
let lastIndex = 0;
|
|
131
|
-
let match;
|
|
132
|
-
while ((match = regex.exec(text)) !== null) {
|
|
133
|
-
if (regex.lastIndex === match.index) {
|
|
134
|
-
regex.lastIndex++;
|
|
135
|
-
}
|
|
136
|
-
if (match.index > lastIndex) {
|
|
137
|
-
tokens.push({
|
|
138
|
-
text: text.substring(lastIndex, match.index),
|
|
139
|
-
type: 'plain',
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
const matchedText = match[0];
|
|
143
|
-
if (match[1]) tokens.push({text: matchedText, type: 'comment'});
|
|
144
|
-
else if (match[2]) tokens.push({text: matchedText, type: 'string'});
|
|
145
|
-
else if (match[3]) tokens.push({text: matchedText, type: 'keyword'});
|
|
146
|
-
else if (match[4]) tokens.push({text: matchedText, type: 'builtin'});
|
|
147
|
-
else if (match[5]) tokens.push({text: matchedText, type: 'number'});
|
|
148
|
-
|
|
149
|
-
lastIndex = regex.lastIndex;
|
|
150
|
-
}
|
|
151
|
-
if (lastIndex < text.length) {
|
|
152
|
-
tokens.push({text: text.substring(lastIndex), type: 'plain'});
|
|
153
|
-
}
|
|
154
|
-
return tokens;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const tokenizeCSS = (text: string) => {
|
|
158
|
-
const tokens: {text: string; type: string}[] = [];
|
|
159
|
-
const regex =
|
|
160
|
-
/(\/\*[\s\S]*?\*\/)|(\.[a-zA-Z0-9_-]+|#[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?=\s*\{))|([a-zA-Z0-9_-]+(?=\s*:))|(:[^;]+;)/g;
|
|
161
|
-
|
|
162
|
-
let lastIndex = 0;
|
|
163
|
-
let match;
|
|
164
|
-
while ((match = regex.exec(text)) !== null) {
|
|
165
|
-
if (regex.lastIndex === match.index) {
|
|
166
|
-
regex.lastIndex++;
|
|
167
|
-
}
|
|
168
|
-
if (match.index > lastIndex) {
|
|
169
|
-
tokens.push({
|
|
170
|
-
text: text.substring(lastIndex, match.index),
|
|
171
|
-
type: 'plain',
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
const matchedText = match[0];
|
|
175
|
-
if (match[1]) tokens.push({text: matchedText, type: 'comment'});
|
|
176
|
-
else if (match[2]) tokens.push({text: matchedText, type: 'selector'});
|
|
177
|
-
else if (match[3]) tokens.push({text: matchedText, type: 'property'});
|
|
178
|
-
else if (match[4]) {
|
|
179
|
-
tokens.push({text: ':', type: 'plain'});
|
|
180
|
-
tokens.push({text: matchedText.substring(1), type: 'value'});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
lastIndex = regex.lastIndex;
|
|
184
|
-
}
|
|
185
|
-
if (lastIndex < text.length) {
|
|
186
|
-
tokens.push({text: text.substring(lastIndex), type: 'plain'});
|
|
187
|
-
}
|
|
188
|
-
return tokens;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const tokenizeHTML = (text: string) => {
|
|
192
|
-
const tokens: {text: string; type: string}[] = [];
|
|
193
|
-
const regex =
|
|
194
|
-
/(<!--[\s\S]*?-->)|(<\/?[a-zA-Z0-9:-]+>?)|(\"(?:\\.|[^\"\\])*\"|\'(?:\\.|[^\'\\])*\')|([a-zA-Z0-9:-]+(?=\s*=))/g;
|
|
195
|
-
|
|
196
|
-
let lastIndex = 0;
|
|
197
|
-
let match;
|
|
198
|
-
while ((match = regex.exec(text)) !== null) {
|
|
199
|
-
if (regex.lastIndex === match.index) {
|
|
200
|
-
regex.lastIndex++;
|
|
201
|
-
}
|
|
202
|
-
if (match.index > lastIndex) {
|
|
203
|
-
tokens.push({
|
|
204
|
-
text: text.substring(lastIndex, match.index),
|
|
205
|
-
type: 'plain',
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
const matchedText = match[0];
|
|
209
|
-
if (match[1]) tokens.push({text: matchedText, type: 'comment'});
|
|
210
|
-
else if (match[2]) tokens.push({text: matchedText, type: 'tag'});
|
|
211
|
-
else if (match[3]) tokens.push({text: matchedText, type: 'string'});
|
|
212
|
-
else if (match[4]) tokens.push({text: matchedText, type: 'attribute'});
|
|
213
|
-
|
|
214
|
-
lastIndex = regex.lastIndex;
|
|
215
|
-
}
|
|
216
|
-
if (lastIndex < text.length) {
|
|
217
|
-
tokens.push({text: text.substring(lastIndex), type: 'plain'});
|
|
218
|
-
}
|
|
219
|
-
return tokens;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const getStyleForType = (type: string) => {
|
|
223
|
-
switch (type) {
|
|
224
|
-
case 'comment':
|
|
225
|
-
return styles.comment;
|
|
226
|
-
case 'string':
|
|
227
|
-
return styles.string;
|
|
228
|
-
case 'keyword':
|
|
229
|
-
return styles.keyword;
|
|
230
|
-
case 'builtin':
|
|
231
|
-
return styles.builtin;
|
|
232
|
-
case 'number':
|
|
233
|
-
return styles.number;
|
|
234
|
-
case 'tag':
|
|
235
|
-
return styles.tag;
|
|
236
|
-
case 'attribute':
|
|
237
|
-
return styles.attribute;
|
|
238
|
-
case 'selector':
|
|
239
|
-
return styles.selector;
|
|
240
|
-
case 'property':
|
|
241
|
-
return styles.property;
|
|
242
|
-
case 'value':
|
|
243
|
-
return styles.value;
|
|
244
|
-
default:
|
|
245
|
-
return [styles.plain, {color: AppColors.primaryBlack}];
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const ArrowUpIcon = ({color = AppColors.slate500, size = 16}: {color?: string; size?: number}) => (
|
|
250
|
-
<Svg width={size} height={size} viewBox="0 0 24 24" fill="none">
|
|
251
|
-
<Path d="M18 15l-6-6-6 6" stroke={color} strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" />
|
|
252
|
-
</Svg>
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
const ArrowDownIcon = ({color = AppColors.slate500, size = 16}: {color?: string; size?: number}) => (
|
|
256
|
-
<Svg width={size} height={size} viewBox="0 0 24 24" fill="none">
|
|
257
|
-
<Path d="M6 9l6 6 6-6" stroke={color} strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" />
|
|
258
|
-
</Svg>
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
const CodeSnippetLine = React.memo(
|
|
262
|
-
({
|
|
263
|
-
line,
|
|
264
|
-
lineIndex,
|
|
265
|
-
language,
|
|
266
|
-
search,
|
|
267
|
-
isActiveMatch,
|
|
268
|
-
}: {
|
|
269
|
-
line: string;
|
|
270
|
-
lineIndex: number;
|
|
271
|
-
language: 'html' | 'css' | 'javascript';
|
|
272
|
-
search: string;
|
|
273
|
-
isActiveMatch: boolean;
|
|
274
|
-
}) => {
|
|
275
|
-
const tokens = useMemo(() => {
|
|
276
|
-
if (language === 'html') return tokenizeHTML(line);
|
|
277
|
-
if (language === 'css') return tokenizeCSS(line);
|
|
278
|
-
return tokenizeJS(line);
|
|
279
|
-
}, [line, language]);
|
|
280
|
-
|
|
281
|
-
const renderTokenText = (text: string, type: string) => {
|
|
282
|
-
const baseStyle = getStyleForType(type);
|
|
283
|
-
if (!search) {
|
|
284
|
-
return <Text style={baseStyle}>{text}</Text>;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const parts = text.split(new RegExp(`(${escapeRegExp(search)})`, 'gi'));
|
|
288
|
-
return (
|
|
289
|
-
<Text style={baseStyle}>
|
|
290
|
-
{parts.map((part, index) => {
|
|
291
|
-
const isMatch = part.toLowerCase() === search.toLowerCase();
|
|
292
|
-
return isMatch ? (
|
|
293
|
-
<Text key={index} style={styles.highlight}>
|
|
294
|
-
{part}
|
|
295
|
-
</Text>
|
|
296
|
-
) : (
|
|
297
|
-
part
|
|
298
|
-
);
|
|
299
|
-
})}
|
|
300
|
-
</Text>
|
|
301
|
-
);
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
return (
|
|
305
|
-
<View style={[styles.lineRow, isActiveMatch && styles.activeMatchRow]}>
|
|
306
|
-
{/* Gutter Line Number */}
|
|
307
|
-
<View style={[styles.gutter, {backgroundColor: AppColors.grayBackground, borderRightColor: AppColors.grayBorderSecondary}, isActiveMatch && styles.activeMatchGutter]}>
|
|
308
|
-
<Text style={[styles.lineNumber, {color: AppColors.grayTextWeak}, isActiveMatch && styles.activeMatchLineNumber]}>{lineIndex + 1}</Text>
|
|
309
|
-
</View>
|
|
310
|
-
|
|
311
|
-
{/* Highlighted Code Line */}
|
|
312
|
-
<View style={styles.codeLine}>
|
|
313
|
-
<Text style={[styles.codeLineText, {color: AppColors.primaryBlack}]}>
|
|
314
|
-
{tokens.length === 0 ? (
|
|
315
|
-
<Text style={[styles.plain, {color: AppColors.primaryBlack}]}> </Text>
|
|
316
|
-
) : (
|
|
317
|
-
tokens.map((token, tokenIdx) => (
|
|
318
|
-
<React.Fragment key={tokenIdx}>
|
|
319
|
-
{renderTokenText(token.text, token.type)}
|
|
320
|
-
</React.Fragment>
|
|
321
|
-
))
|
|
322
|
-
)}
|
|
323
|
-
</Text>
|
|
324
|
-
</View>
|
|
325
|
-
</View>
|
|
326
|
-
);
|
|
327
|
-
},
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
const CodeSnippet: React.FC<CodeSnippetProps> = ({
|
|
331
|
-
code,
|
|
332
|
-
language,
|
|
333
|
-
search,
|
|
334
|
-
}) => {
|
|
335
|
-
const [searchQuery, setSearchQuery] = useState('');
|
|
336
|
-
const [debouncedQuery, setDebouncedQuery] = useState('');
|
|
337
|
-
const [currentMatchIdx, setCurrentMatchIdx] = useState(-1);
|
|
338
|
-
const [visibleLinesCount, setVisibleLinesCount] = useState(200);
|
|
339
|
-
|
|
340
|
-
const flatListRef = useRef<FlatList>(null);
|
|
341
|
-
|
|
342
|
-
// Sync prop search to searchQuery
|
|
343
|
-
useEffect(() => {
|
|
344
|
-
if (search !== undefined) {
|
|
345
|
-
setSearchQuery(search);
|
|
346
|
-
}
|
|
347
|
-
}, [search]);
|
|
348
|
-
|
|
349
|
-
// Debounce search query updates
|
|
350
|
-
useEffect(() => {
|
|
351
|
-
const timer = setTimeout(() => {
|
|
352
|
-
setDebouncedQuery(searchQuery);
|
|
353
|
-
}, 300);
|
|
354
|
-
return () => clearTimeout(timer);
|
|
355
|
-
}, [searchQuery]);
|
|
356
|
-
|
|
357
|
-
// If code is extremely large (e.g. > 150KB), skip the pretty printers
|
|
358
|
-
// to avoid blocking the single JS thread.
|
|
359
|
-
const formattedCode = useMemo(() => {
|
|
360
|
-
if (!code) return '';
|
|
361
|
-
if (code.length > 150000) {
|
|
362
|
-
return code;
|
|
363
|
-
}
|
|
364
|
-
if (language === 'html') return formatHTML(code);
|
|
365
|
-
if (language === 'css') return formatCSS(code);
|
|
366
|
-
if (language === 'javascript') return formatJS(code);
|
|
367
|
-
return code;
|
|
368
|
-
}, [code, language]);
|
|
369
|
-
|
|
370
|
-
const lines = useMemo(() => {
|
|
371
|
-
if (!formattedCode) return [];
|
|
372
|
-
return formattedCode.split(/\r?\n/);
|
|
373
|
-
}, [formattedCode]);
|
|
374
|
-
|
|
375
|
-
// Find all line indices matching the search query
|
|
376
|
-
const matches = useMemo(() => {
|
|
377
|
-
if (!debouncedQuery.trim() || debouncedQuery.length < 2) return [];
|
|
378
|
-
const query = debouncedQuery.toLowerCase();
|
|
379
|
-
const indices: number[] = [];
|
|
380
|
-
for (let i = 0; i < lines.length; i++) {
|
|
381
|
-
if (lines[i].toLowerCase().includes(query)) {
|
|
382
|
-
indices.push(i);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return indices;
|
|
386
|
-
}, [debouncedQuery, lines]);
|
|
387
|
-
|
|
388
|
-
// Reset scroll and states on code/language changes
|
|
389
|
-
useEffect(() => {
|
|
390
|
-
setVisibleLinesCount(200);
|
|
391
|
-
setSearchQuery(search || '');
|
|
392
|
-
setCurrentMatchIdx(-1);
|
|
393
|
-
}, [code, language]);
|
|
394
|
-
|
|
395
|
-
// Auto-scroll to the first match when search query returns matches
|
|
396
|
-
useEffect(() => {
|
|
397
|
-
if (matches.length > 0) {
|
|
398
|
-
setCurrentMatchIdx(0);
|
|
399
|
-
scrollToMatch(0);
|
|
400
|
-
} else {
|
|
401
|
-
setCurrentMatchIdx(-1);
|
|
402
|
-
}
|
|
403
|
-
}, [matches]);
|
|
404
|
-
|
|
405
|
-
const scrollToMatch = (matchIdx: number) => {
|
|
406
|
-
if (matches.length === 0 || matchIdx < 0 || matchIdx >= matches.length) return;
|
|
407
|
-
const lineIdx = matches[matchIdx];
|
|
408
|
-
|
|
409
|
-
// Ensure the targeted index is loaded in FlatList
|
|
410
|
-
if (lineIdx >= visibleLinesCount) {
|
|
411
|
-
setVisibleLinesCount(lineIdx + 100);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// Schedule scroll after state has applied
|
|
415
|
-
setTimeout(() => {
|
|
416
|
-
try {
|
|
417
|
-
flatListRef.current?.scrollToIndex({
|
|
418
|
-
index: lineIdx,
|
|
419
|
-
animated: false,
|
|
420
|
-
viewPosition: 0.3,
|
|
421
|
-
});
|
|
422
|
-
} catch (e) {
|
|
423
|
-
// Fallback recovery is handled by onScrollToIndexFailed
|
|
424
|
-
}
|
|
425
|
-
}, 50);
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
const onScrollToIndexFailed = (error: any) => {
|
|
429
|
-
flatListRef.current?.scrollToOffset({
|
|
430
|
-
offset: error.averageItemLength * error.index,
|
|
431
|
-
animated: false,
|
|
432
|
-
});
|
|
433
|
-
setTimeout(() => {
|
|
434
|
-
try {
|
|
435
|
-
flatListRef.current?.scrollToIndex({
|
|
436
|
-
index: error.index,
|
|
437
|
-
animated: false,
|
|
438
|
-
viewPosition: 0.3,
|
|
439
|
-
});
|
|
440
|
-
} catch (err) {
|
|
441
|
-
console.warn('Scroll to line index failed after fallback retry:', err);
|
|
442
|
-
}
|
|
443
|
-
}, 60);
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
const handleNextMatch = () => {
|
|
447
|
-
if (matches.length === 0) return;
|
|
448
|
-
const nextIdx = (currentMatchIdx + 1) % matches.length;
|
|
449
|
-
setCurrentMatchIdx(nextIdx);
|
|
450
|
-
scrollToMatch(nextIdx);
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
const handlePrevMatch = () => {
|
|
454
|
-
if (matches.length === 0) return;
|
|
455
|
-
const prevIdx = (currentMatchIdx - 1 + matches.length) % matches.length;
|
|
456
|
-
setCurrentMatchIdx(prevIdx);
|
|
457
|
-
scrollToMatch(prevIdx);
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const visibleLines = useMemo(() => {
|
|
461
|
-
return lines.slice(0, visibleLinesCount);
|
|
462
|
-
}, [lines, visibleLinesCount]);
|
|
463
|
-
|
|
464
|
-
const handleEndReached = () => {
|
|
465
|
-
if (visibleLinesCount < lines.length) {
|
|
466
|
-
setVisibleLinesCount(prev => Math.min(prev + 150, lines.length));
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
const renderLine = ({item, index}: {item: string; index: number}) => {
|
|
471
|
-
const isActiveMatch = matches.length > 0 && currentMatchIdx >= 0 && index === matches[currentMatchIdx];
|
|
472
|
-
return (
|
|
473
|
-
<CodeSnippetLine
|
|
474
|
-
line={item}
|
|
475
|
-
lineIndex={index}
|
|
476
|
-
language={language}
|
|
477
|
-
search={debouncedQuery}
|
|
478
|
-
isActiveMatch={isActiveMatch}
|
|
479
|
-
/>
|
|
480
|
-
);
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
return (
|
|
484
|
-
<View style={{flex: 1}}>
|
|
485
|
-
{/* Search Header Row */}
|
|
486
|
-
<View style={styles.searchRow}>
|
|
487
|
-
<View style={[styles.searchBar, {backgroundColor: AppColors.primaryLight, borderColor: AppColors.grayBorderSecondary}]}>
|
|
488
|
-
<SearchIcon color={AppColors.grayTextWeak} size={15} />
|
|
489
|
-
<TextInput
|
|
490
|
-
placeholder={`Search ${language.toUpperCase()}...`}
|
|
491
|
-
placeholderTextColor={AppColors.grayTextWeak}
|
|
492
|
-
value={searchQuery}
|
|
493
|
-
onChangeText={setSearchQuery}
|
|
494
|
-
style={[styles.searchInput, {color: AppColors.primaryBlack}]}
|
|
495
|
-
autoCorrect={false}
|
|
496
|
-
autoCapitalize="none"
|
|
497
|
-
/>
|
|
498
|
-
|
|
499
|
-
{/* Matches Info */}
|
|
500
|
-
{debouncedQuery.length >= 2 && (
|
|
501
|
-
<Text style={[styles.matchCountText, {backgroundColor: AppColors.grayBackground, color: AppColors.grayTextWeak}]}>
|
|
502
|
-
{matches.length > 0 ? `${currentMatchIdx + 1}/${matches.length}` : '0/0'}
|
|
503
|
-
</Text>
|
|
504
|
-
)}
|
|
505
|
-
|
|
506
|
-
{searchQuery.length > 0 && (
|
|
507
|
-
<Pressable onPress={() => setSearchQuery('')} hitSlop={8} style={styles.clearBtn}>
|
|
508
|
-
<ClearIcon color={AppColors.grayTextWeak} size={12} />
|
|
509
|
-
</Pressable>
|
|
510
|
-
)}
|
|
511
|
-
</View>
|
|
512
|
-
|
|
513
|
-
{/* Up / Down Arrow Navigation Buttons */}
|
|
514
|
-
{matches.length > 0 && (
|
|
515
|
-
<View style={[styles.navArrowsGroup, {backgroundColor: AppColors.primaryLight, borderColor: AppColors.grayBorderSecondary}]}>
|
|
516
|
-
<TouchableScale onPress={handlePrevMatch} hitSlop={8} style={styles.navArrowBtn}>
|
|
517
|
-
<ArrowUpIcon color={AppColors.grayTextStrong} size={14} />
|
|
518
|
-
</TouchableScale>
|
|
519
|
-
<TouchableScale onPress={handleNextMatch} hitSlop={8} style={styles.navArrowBtn}>
|
|
520
|
-
<ArrowDownIcon color={AppColors.grayTextStrong} size={14} />
|
|
521
|
-
</TouchableScale>
|
|
522
|
-
</View>
|
|
523
|
-
)}
|
|
524
|
-
|
|
525
|
-
<CopyButton value={code} label={`${language.toUpperCase()} Source`} />
|
|
526
|
-
</View>
|
|
527
|
-
|
|
528
|
-
{/* Code Snippet list container */}
|
|
529
|
-
<View style={[styles.container, {backgroundColor: AppColors.grayBackground, borderColor: AppColors.grayBorderSecondary}]}>
|
|
530
|
-
<FlatList
|
|
531
|
-
ref={flatListRef}
|
|
532
|
-
data={visibleLines}
|
|
533
|
-
renderItem={renderLine}
|
|
534
|
-
keyExtractor={(_, index) => String(index)}
|
|
535
|
-
maxToRenderPerBatch={30}
|
|
536
|
-
windowSize={5}
|
|
537
|
-
initialNumToRender={50}
|
|
538
|
-
removeClippedSubviews={Platform.OS === 'android'}
|
|
539
|
-
onEndReached={handleEndReached}
|
|
540
|
-
onEndReachedThreshold={0.5}
|
|
541
|
-
onScrollToIndexFailed={onScrollToIndexFailed}
|
|
542
|
-
/>
|
|
543
|
-
</View>
|
|
544
|
-
</View>
|
|
545
|
-
);
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
const monoFont = AppFonts.interRegular;
|
|
549
|
-
|
|
550
|
-
const styles = StyleSheet.create({
|
|
551
|
-
container: {
|
|
552
|
-
flex: 1,
|
|
553
|
-
backgroundColor: AppColors.slate50,
|
|
554
|
-
borderRadius: 8,
|
|
555
|
-
borderWidth: 1,
|
|
556
|
-
borderColor: AppColors.slate200,
|
|
557
|
-
overflow: 'hidden',
|
|
558
|
-
},
|
|
559
|
-
searchRow: {
|
|
560
|
-
flexDirection: 'row',
|
|
561
|
-
alignItems: 'center',
|
|
562
|
-
marginBottom: 6,
|
|
563
|
-
gap: 8,
|
|
564
|
-
},
|
|
565
|
-
searchBar: {
|
|
566
|
-
flex: 1,
|
|
567
|
-
flexDirection: 'row',
|
|
568
|
-
alignItems: 'center',
|
|
569
|
-
backgroundColor: AppColors.white,
|
|
570
|
-
borderRadius: 8,
|
|
571
|
-
borderWidth: 1,
|
|
572
|
-
borderColor: AppColors.slate200,
|
|
573
|
-
paddingHorizontal: 8,
|
|
574
|
-
height: 32,
|
|
575
|
-
},
|
|
576
|
-
searchInput: {
|
|
577
|
-
flex: 1,
|
|
578
|
-
fontFamily: AppFonts.interRegular,
|
|
579
|
-
fontSize: 12,
|
|
580
|
-
color: AppColors.slate900,
|
|
581
|
-
marginLeft: 6,
|
|
582
|
-
paddingVertical: 0,
|
|
583
|
-
},
|
|
584
|
-
matchCountText: {
|
|
585
|
-
fontFamily: AppFonts.interMedium,
|
|
586
|
-
fontSize: 10,
|
|
587
|
-
color: AppColors.slate500,
|
|
588
|
-
marginHorizontal: 6,
|
|
589
|
-
backgroundColor: AppColors.slate100,
|
|
590
|
-
paddingHorizontal: 6,
|
|
591
|
-
paddingVertical: 2,
|
|
592
|
-
borderRadius: 4,
|
|
593
|
-
},
|
|
594
|
-
clearBtn: {
|
|
595
|
-
padding: 4,
|
|
596
|
-
},
|
|
597
|
-
navArrowsGroup: {
|
|
598
|
-
flexDirection: 'row',
|
|
599
|
-
alignItems: 'center',
|
|
600
|
-
backgroundColor: AppColors.white,
|
|
601
|
-
borderRadius: 8,
|
|
602
|
-
borderWidth: 1,
|
|
603
|
-
borderColor: AppColors.slate200,
|
|
604
|
-
height: 32,
|
|
605
|
-
paddingHorizontal: 2,
|
|
606
|
-
},
|
|
607
|
-
navArrowBtn: {
|
|
608
|
-
padding: 5,
|
|
609
|
-
borderRadius: 6,
|
|
610
|
-
alignItems: 'center',
|
|
611
|
-
justifyContent: 'center',
|
|
612
|
-
},
|
|
613
|
-
lineRow: {
|
|
614
|
-
flexDirection: 'row',
|
|
615
|
-
alignItems: 'stretch',
|
|
616
|
-
minHeight: 20,
|
|
617
|
-
paddingVertical: 1,
|
|
618
|
-
},
|
|
619
|
-
activeMatchRow: {
|
|
620
|
-
backgroundColor: `${AppColors.amber600}38`,
|
|
621
|
-
borderLeftWidth: 4,
|
|
622
|
-
borderLeftColor: AppColors.amber600,
|
|
623
|
-
},
|
|
624
|
-
gutter: {
|
|
625
|
-
width: 40,
|
|
626
|
-
backgroundColor: AppColors.slate100,
|
|
627
|
-
borderRightWidth: 1,
|
|
628
|
-
borderRightColor: AppColors.slate200,
|
|
629
|
-
justifyContent: 'flex-start',
|
|
630
|
-
alignItems: 'flex-end',
|
|
631
|
-
paddingRight: 6,
|
|
632
|
-
paddingTop: 1,
|
|
633
|
-
},
|
|
634
|
-
activeMatchGutter: {
|
|
635
|
-
backgroundColor: `${AppColors.amber600}59`,
|
|
636
|
-
borderRightColor: `${AppColors.amber600}80`,
|
|
637
|
-
},
|
|
638
|
-
lineNumber: {
|
|
639
|
-
fontFamily: monoFont,
|
|
640
|
-
fontSize: 9,
|
|
641
|
-
color: AppColors.slate400,
|
|
642
|
-
},
|
|
643
|
-
activeMatchLineNumber: {
|
|
644
|
-
color: AppColors.amber800,
|
|
645
|
-
fontWeight: 'bold',
|
|
646
|
-
},
|
|
647
|
-
codeLine: {
|
|
648
|
-
flex: 1,
|
|
649
|
-
paddingLeft: 10,
|
|
650
|
-
paddingRight: 12,
|
|
651
|
-
justifyContent: 'center',
|
|
652
|
-
},
|
|
653
|
-
codeLineText: {
|
|
654
|
-
fontFamily: monoFont,
|
|
655
|
-
fontSize: 10.5,
|
|
656
|
-
color: AppColors.slate700,
|
|
657
|
-
flexWrap: 'wrap',
|
|
658
|
-
},
|
|
659
|
-
plain: {
|
|
660
|
-
fontFamily: monoFont,
|
|
661
|
-
fontSize: 10.5,
|
|
662
|
-
color: AppColors.slate700,
|
|
663
|
-
},
|
|
664
|
-
comment: {
|
|
665
|
-
fontFamily: monoFont,
|
|
666
|
-
fontSize: 10.5,
|
|
667
|
-
color: AppColors.slate500,
|
|
668
|
-
fontStyle: 'italic',
|
|
669
|
-
},
|
|
670
|
-
string: {
|
|
671
|
-
fontFamily: monoFont,
|
|
672
|
-
fontSize: 10.5,
|
|
673
|
-
color: AppColors.amber700,
|
|
674
|
-
},
|
|
675
|
-
keyword: {
|
|
676
|
-
fontFamily: monoFont,
|
|
677
|
-
fontSize: 10.5,
|
|
678
|
-
color: AppColors.violet600,
|
|
679
|
-
fontWeight: 'bold',
|
|
680
|
-
},
|
|
681
|
-
builtin: {
|
|
682
|
-
fontFamily: monoFont,
|
|
683
|
-
fontSize: 10.5,
|
|
684
|
-
color: AppColors.teal600,
|
|
685
|
-
},
|
|
686
|
-
number: {
|
|
687
|
-
fontFamily: monoFont,
|
|
688
|
-
fontSize: 10.5,
|
|
689
|
-
color: AppColors.blue600,
|
|
690
|
-
},
|
|
691
|
-
tag: {
|
|
692
|
-
fontFamily: monoFont,
|
|
693
|
-
fontSize: 10.5,
|
|
694
|
-
color: AppColors.indigo600,
|
|
695
|
-
fontWeight: 'bold',
|
|
696
|
-
},
|
|
697
|
-
attribute: {
|
|
698
|
-
fontFamily: monoFont,
|
|
699
|
-
fontSize: 10.5,
|
|
700
|
-
color: AppColors.teal600,
|
|
701
|
-
},
|
|
702
|
-
selector: {
|
|
703
|
-
fontFamily: monoFont,
|
|
704
|
-
fontSize: 10.5,
|
|
705
|
-
color: AppColors.violet600,
|
|
706
|
-
fontWeight: 'bold',
|
|
707
|
-
},
|
|
708
|
-
property: {
|
|
709
|
-
fontFamily: monoFont,
|
|
710
|
-
fontSize: 10.5,
|
|
711
|
-
color: AppColors.teal600,
|
|
712
|
-
},
|
|
713
|
-
value: {
|
|
714
|
-
fontFamily: monoFont,
|
|
715
|
-
fontSize: 10.5,
|
|
716
|
-
color: AppColors.orange600,
|
|
717
|
-
},
|
|
718
|
-
highlight: {
|
|
719
|
-
backgroundColor: AppColors.highlightYellow,
|
|
720
|
-
color: AppColors.black,
|
|
721
|
-
},
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
export default CodeSnippet;
|
|
725
|
-
|