chahuadev commited on
Commit ·
f68c02e
0
Parent(s):
chore: sync latest local updates
Browse files- .gitignore +44 -0
- App.js +54 -0
- app.json +33 -0
- assets/monaco.html +662 -0
- babel.config.js +7 -0
- dev-commands.bat +266 -0
- index.js +3 -0
- package-lock.json +0 -0
- package.json +35 -0
- src/screens/EditorScreen.js +502 -0
- src/screens/FileExplorerScreen.js +384 -0
- src/screens/SplashScreen.js +186 -0
- src/theme.js +82 -0
.gitignore
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
|
| 2 |
+
|
| 3 |
+
# dependencies
|
| 4 |
+
node_modules/
|
| 5 |
+
|
| 6 |
+
# Expo
|
| 7 |
+
.expo/
|
| 8 |
+
dist/
|
| 9 |
+
web-build/
|
| 10 |
+
expo-env.d.ts
|
| 11 |
+
|
| 12 |
+
# Native
|
| 13 |
+
.kotlin/
|
| 14 |
+
*.orig.*
|
| 15 |
+
*.jks
|
| 16 |
+
*.p8
|
| 17 |
+
*.p12
|
| 18 |
+
*.key
|
| 19 |
+
*.mobileprovision
|
| 20 |
+
|
| 21 |
+
# Metro
|
| 22 |
+
.metro-health-check*
|
| 23 |
+
|
| 24 |
+
# debug
|
| 25 |
+
npm-debug.*
|
| 26 |
+
yarn-debug.*
|
| 27 |
+
yarn-error.*
|
| 28 |
+
|
| 29 |
+
# macOS
|
| 30 |
+
.DS_Store
|
| 31 |
+
*.pem
|
| 32 |
+
|
| 33 |
+
# local env files
|
| 34 |
+
.env*.local
|
| 35 |
+
|
| 36 |
+
# typescript
|
| 37 |
+
*.tsbuildinfo
|
| 38 |
+
|
| 39 |
+
# generated native folders
|
| 40 |
+
/ios
|
| 41 |
+
/android
|
| 42 |
+
.idea/
|
| 43 |
+
/asset/icon.pngdev-launcher.exe
|
| 44 |
+
assets/icon.png
|
App.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import 'react-native-gesture-handler';
|
| 2 |
+
import React, { useState } from 'react';
|
| 3 |
+
import { StatusBar } from 'expo-status-bar';
|
| 4 |
+
import SplashScreen from './src/screens/SplashScreen';
|
| 5 |
+
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
|
| 6 |
+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
| 7 |
+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
| 8 |
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
| 9 |
+
import FileExplorerScreen from './src/screens/FileExplorerScreen';
|
| 10 |
+
import EditorScreen from './src/screens/EditorScreen';
|
| 11 |
+
import { theme } from './src/theme';
|
| 12 |
+
|
| 13 |
+
const Stack = createNativeStackNavigator();
|
| 14 |
+
|
| 15 |
+
const navTheme = {
|
| 16 |
+
...DefaultTheme,
|
| 17 |
+
colors: {
|
| 18 |
+
...DefaultTheme.colors,
|
| 19 |
+
background: theme.colors.bg,
|
| 20 |
+
card: theme.colors.surface,
|
| 21 |
+
text: theme.colors.text,
|
| 22 |
+
border: theme.colors.border,
|
| 23 |
+
primary: theme.colors.accent,
|
| 24 |
+
},
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
export default function App() {
|
| 28 |
+
const [showSplash, setShowSplash] = useState(true)
|
| 29 |
+
|
| 30 |
+
if (showSplash) {
|
| 31 |
+
return (
|
| 32 |
+
<GestureHandlerRootView style={{ flex: 1 }}>
|
| 33 |
+
<SafeAreaProvider>
|
| 34 |
+
<StatusBar style="light" backgroundColor="#08090f" />
|
| 35 |
+
<SplashScreen onDone={() => setShowSplash(false)} />
|
| 36 |
+
</SafeAreaProvider>
|
| 37 |
+
</GestureHandlerRootView>
|
| 38 |
+
)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return (
|
| 42 |
+
<GestureHandlerRootView style={{ flex: 1 }}>
|
| 43 |
+
<SafeAreaProvider>
|
| 44 |
+
<NavigationContainer theme={navTheme}>
|
| 45 |
+
<StatusBar style="light" backgroundColor={theme.colors.bg} />
|
| 46 |
+
<Stack.Navigator screenOptions={{ headerShown: false, animation: 'slide_from_right' }}>
|
| 47 |
+
<Stack.Screen name="FileExplorer" component={FileExplorerScreen} />
|
| 48 |
+
<Stack.Screen name="Editor" component={EditorScreen} />
|
| 49 |
+
</Stack.Navigator>
|
| 50 |
+
</NavigationContainer>
|
| 51 |
+
</SafeAreaProvider>
|
| 52 |
+
</GestureHandlerRootView>
|
| 53 |
+
);
|
| 54 |
+
}
|
app.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"expo": {
|
| 3 |
+
"name": "Chahuadev Code Editor",
|
| 4 |
+
"slug": "chahuadev-code-editor",
|
| 5 |
+
"version": "1.0.0",
|
| 6 |
+
"orientation": "default",
|
| 7 |
+
"icon": "./assets/icon.png",
|
| 8 |
+
"userInterfaceStyle": "dark",
|
| 9 |
+
"splash": {
|
| 10 |
+
"image": "./assets/icon.png",
|
| 11 |
+
"resizeMode": "contain",
|
| 12 |
+
"backgroundColor": "#0e0e14"
|
| 13 |
+
},
|
| 14 |
+
"ios": {
|
| 15 |
+
"supportsTablet": true
|
| 16 |
+
},
|
| 17 |
+
"android": {
|
| 18 |
+
"package": "com.chahuadev.codeeditor",
|
| 19 |
+
"adaptiveIcon": {
|
| 20 |
+
"backgroundColor": "#0e0e14",
|
| 21 |
+
"foregroundImage": "./assets/icon.png"
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
"web": {
|
| 25 |
+
"favicon": "./assets/icon.png"
|
| 26 |
+
},
|
| 27 |
+
"plugins": [
|
| 28 |
+
[
|
| 29 |
+
"expo-file-system"
|
| 30 |
+
]
|
| 31 |
+
]
|
| 32 |
+
}
|
| 33 |
+
}
|
assets/monaco.html
ADDED
|
@@ -0,0 +1,662 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
| 6 |
+
<title>Code Editor</title>
|
| 7 |
+
<style>
|
| 8 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 9 |
+
html, body { width: 100%; height: 100%; background: #0e0e14; overflow: hidden; }
|
| 10 |
+
#editor-container { width: 100%; height: 100%; }
|
| 11 |
+
#loading {
|
| 12 |
+
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
|
| 13 |
+
display: flex; align-items: center; justify-content: center;
|
| 14 |
+
flex-direction: column; gap: 14px;
|
| 15 |
+
background: #0e0e14; color: #6ee7b7; font-family: 'Courier New', monospace; font-size: 14px;
|
| 16 |
+
z-index: 9999;
|
| 17 |
+
}
|
| 18 |
+
.spin {
|
| 19 |
+
width: 32px; height: 32px;
|
| 20 |
+
border: 3px solid #2d2d44; border-top-color: #818cf8;
|
| 21 |
+
border-radius: 50%; animation: spin 0.9s linear infinite;
|
| 22 |
+
}
|
| 23 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
| 24 |
+
/* Make Monaco's inputarea big enough for Android to detect as a real text field */
|
| 25 |
+
.monaco-editor .inputarea {
|
| 26 |
+
pointer-events: auto !important;
|
| 27 |
+
width: 50px !important;
|
| 28 |
+
height: 50px !important;
|
| 29 |
+
opacity: 0.01 !important;
|
| 30 |
+
}
|
| 31 |
+
/* Error Lens inline decoration styles */
|
| 32 |
+
.el-error { color: #f87171 !important; font-style: italic; font-size: 12px !important; pointer-events: none; }
|
| 33 |
+
.el-warn { color: #fbbf24 !important; font-style: italic; font-size: 12px !important; pointer-events: none; }
|
| 34 |
+
.el-info { color: #38bdf8 !important; font-style: italic; font-size: 12px !important; pointer-events: none; }
|
| 35 |
+
/* TODO / FIXME / NOTE highlight decorations */
|
| 36 |
+
.td-todo { background: rgba(251,191,36,0.12); border-bottom: 1px solid #fbbf24cc; color: #fbbf24; font-weight: 600; }
|
| 37 |
+
.td-fixme { background: rgba(248,113,113,0.12); border-bottom: 1px solid #f87171cc; color: #f87171; font-weight: 600; }
|
| 38 |
+
.td-note { background: rgba(56,189,248,0.12); border-bottom: 1px solid #38bdf8cc; color: #38bdf8; font-weight: 600; }
|
| 39 |
+
</style>
|
| 40 |
+
</head>
|
| 41 |
+
<body>
|
| 42 |
+
<div id="loading"><div class="spin"></div>Loading Monaco…</div>
|
| 43 |
+
<div id="editor-container"></div>
|
| 44 |
+
|
| 45 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.46.0/min/vs/loader.min.js"></script>
|
| 46 |
+
<script>
|
| 47 |
+
(function () {
|
| 48 |
+
var editor = null;
|
| 49 |
+
var currentFontSize = 15;
|
| 50 |
+
var wordWrapEnabled = false;
|
| 51 |
+
var errorLensIds = [];
|
| 52 |
+
var prettierReady = false;
|
| 53 |
+
var prettierLoading = false;
|
| 54 |
+
var todoIds = [];
|
| 55 |
+
var todoDebounce = null;
|
| 56 |
+
var emmetReady = false;
|
| 57 |
+
var emmetLoading = false;
|
| 58 |
+
|
| 59 |
+
// ─── Load Monaco ───────────────────────────────────────────────────────────
|
| 60 |
+
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.46.0/min/vs' } });
|
| 61 |
+
require(['vs/editor/editor.main'], function () {
|
| 62 |
+
document.getElementById('loading').style.display = 'none';
|
| 63 |
+
|
| 64 |
+
// ── Theme ──────────────────────────────────────────────────────────────
|
| 65 |
+
monaco.editor.defineTheme('cha-dark', {
|
| 66 |
+
base: 'vs-dark', inherit: true,
|
| 67 |
+
rules: [
|
| 68 |
+
{ token: 'comment', foreground: '6b7280', fontStyle: 'italic' },
|
| 69 |
+
{ token: 'keyword', foreground: 'c084fc' },
|
| 70 |
+
{ token: 'keyword.control', foreground: 'f472b6' },
|
| 71 |
+
{ token: 'string', foreground: '6ee7b7' },
|
| 72 |
+
{ token: 'string.escape', foreground: 'fb923c' },
|
| 73 |
+
{ token: 'number', foreground: 'fb923c' },
|
| 74 |
+
{ token: 'regexp', foreground: 'f87171' },
|
| 75 |
+
{ token: 'type', foreground: '38bdf8' },
|
| 76 |
+
{ token: 'type.identifier', foreground: '38bdf8' },
|
| 77 |
+
{ token: 'class', foreground: 'fbbf24' },
|
| 78 |
+
{ token: 'function', foreground: 'fbbf24' },
|
| 79 |
+
{ token: 'variable', foreground: 'e2e8f0' },
|
| 80 |
+
{ token: 'variable.predefined', foreground: 'f87171' },
|
| 81 |
+
{ token: 'constant', foreground: 'fb923c' },
|
| 82 |
+
{ token: 'tag', foreground: 'f87171' },
|
| 83 |
+
{ token: 'tag.id', foreground: 'fbbf24' },
|
| 84 |
+
{ token: 'tag.class', foreground: '6ee7b7' },
|
| 85 |
+
{ token: 'attribute.name', foreground: '818cf8' },
|
| 86 |
+
{ token: 'attribute.value', foreground: '6ee7b7' },
|
| 87 |
+
{ token: 'delimiter', foreground: '94a3b8' },
|
| 88 |
+
{ token: 'operator', foreground: '94a3b8' },
|
| 89 |
+
{ token: 'namespace', foreground: '38bdf8' },
|
| 90 |
+
{ token: 'constructor', foreground: 'fbbf24' },
|
| 91 |
+
{ token: 'identifier', foreground: 'e2e8f0' },
|
| 92 |
+
{ token: 'annotation', foreground: 'f472b6' },
|
| 93 |
+
{ token: 'decorator', foreground: 'f472b6' },
|
| 94 |
+
],
|
| 95 |
+
colors: {
|
| 96 |
+
'editor.background': '#0e0e14',
|
| 97 |
+
'editor.foreground': '#e2e8f0',
|
| 98 |
+
'editor.lineHighlightBackground': '#1a1a2e',
|
| 99 |
+
'editor.lineHighlightBorder': '#2d2d4460',
|
| 100 |
+
'editorLineNumber.foreground': '#374151',
|
| 101 |
+
'editorLineNumber.activeForeground': '#818cf8',
|
| 102 |
+
'editor.selectionBackground': '#818cf840',
|
| 103 |
+
'editor.inactiveSelectionBackground': '#818cf820',
|
| 104 |
+
'editor.wordHighlightBackground': '#818cf820',
|
| 105 |
+
'editor.findMatchBackground': '#fbbf2440',
|
| 106 |
+
'editor.findMatchHighlightBackground': '#fbbf2420',
|
| 107 |
+
'editorCursor.foreground': '#6ee7b7',
|
| 108 |
+
'editorWidget.background': '#1a1a2e',
|
| 109 |
+
'editorWidget.border': '#2d2d44',
|
| 110 |
+
'editorSuggestWidget.background': '#1a1a2e',
|
| 111 |
+
'editorSuggestWidget.border': '#2d2d44',
|
| 112 |
+
'editorSuggestWidget.foreground': '#e2e8f0',
|
| 113 |
+
'editorSuggestWidget.selectedBackground': '#2d2d44',
|
| 114 |
+
'editorSuggestWidget.highlightForeground': '#818cf8',
|
| 115 |
+
'editorGutter.background': '#0e0e14',
|
| 116 |
+
'scrollbarSlider.background': '#2d2d44aa',
|
| 117 |
+
'scrollbarSlider.hoverBackground': '#818cf860',
|
| 118 |
+
'scrollbarSlider.activeBackground': '#818cf8aa',
|
| 119 |
+
'editorError.foreground': '#f87171',
|
| 120 |
+
'editorWarning.foreground': '#fbbf24',
|
| 121 |
+
'editorInfo.foreground': '#38bdf8',
|
| 122 |
+
'editorHint.foreground': '#6ee7b780',
|
| 123 |
+
'editorOverviewRuler.errorForeground': '#f87171',
|
| 124 |
+
'editorOverviewRuler.warningForeground': '#fbbf24',
|
| 125 |
+
'editorBracketMatch.background': '#818cf820',
|
| 126 |
+
'editorBracketMatch.border': '#818cf8',
|
| 127 |
+
'editorIndentGuide.background1': '#2d2d44',
|
| 128 |
+
'editorIndentGuide.activeBackground1': '#818cf840',
|
| 129 |
+
'list.activeSelectionBackground': '#2d2d44',
|
| 130 |
+
'list.hoverBackground': '#1a1a2e',
|
| 131 |
+
'peekView.border': '#818cf8',
|
| 132 |
+
'peekViewResult.background': '#1a1a2e',
|
| 133 |
+
'peekViewEditor.background': '#0e0e14',
|
| 134 |
+
}
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
// ── Create Editor ──────────────────────────────────────────────────────
|
| 138 |
+
editor = monaco.editor.create(document.getElementById('editor-container'), {
|
| 139 |
+
value: '', language: 'javascript', theme: 'cha-dark',
|
| 140 |
+
fontSize: currentFontSize,
|
| 141 |
+
fontFamily: "'JetBrains Mono', 'Fira Code', 'Consolas', 'Courier New', monospace",
|
| 142 |
+
fontLigatures: true,
|
| 143 |
+
lineHeight: 22,
|
| 144 |
+
letterSpacing: 0.3,
|
| 145 |
+
lineNumbers: function(n) {
|
| 146 |
+
if (n >= 10000) return Math.floor(n/1000) + 'k';
|
| 147 |
+
if (n >= 1000) return (n/1000).toFixed(1).replace(/\.0$/,'') + 'k';
|
| 148 |
+
return String(n);
|
| 149 |
+
},
|
| 150 |
+
lineNumbersMinChars: 2,
|
| 151 |
+
lineDecorationsWidth: 2,
|
| 152 |
+
wordWrap: 'off',
|
| 153 |
+
minimap: { enabled: false },
|
| 154 |
+
scrollbar: {
|
| 155 |
+
vertical: 'auto', horizontal: 'auto',
|
| 156 |
+
verticalScrollbarSize: 5, horizontalScrollbarSize: 5,
|
| 157 |
+
useShadows: false,
|
| 158 |
+
},
|
| 159 |
+
automaticLayout: true,
|
| 160 |
+
suggestOnTriggerCharacters: true,
|
| 161 |
+
quickSuggestions: { other: true, comments: false, strings: false },
|
| 162 |
+
quickSuggestionsDelay: 200,
|
| 163 |
+
parameterHints: { enabled: true },
|
| 164 |
+
tabSize: 2, insertSpaces: true, detectIndentation: true,
|
| 165 |
+
renderWhitespace: 'selection',
|
| 166 |
+
bracketPairColorization: { enabled: true, independentColorPoolPerBracketType: true },
|
| 167 |
+
guides: { indentation: true, bracketPairs: true },
|
| 168 |
+
autoClosingBrackets: 'always',
|
| 169 |
+
autoClosingQuotes: 'always',
|
| 170 |
+
autoSurround: 'quotes',
|
| 171 |
+
matchBrackets: 'always',
|
| 172 |
+
formatOnType: false,
|
| 173 |
+
scrollBeyondLastLine: false,
|
| 174 |
+
padding: { top: 12, bottom: 80 },
|
| 175 |
+
cursorBlinking: 'smooth',
|
| 176 |
+
cursorSmoothCaretAnimation: 'on',
|
| 177 |
+
smoothScrolling: true,
|
| 178 |
+
contextmenu: false,
|
| 179 |
+
mouseWheelZoom: false,
|
| 180 |
+
folding: true,
|
| 181 |
+
showFoldingControls: 'mouseover',
|
| 182 |
+
foldingStrategy: 'indentation',
|
| 183 |
+
glyphMargin: false,
|
| 184 |
+
colorDecorators: true,
|
| 185 |
+
renderLineHighlight: 'line',
|
| 186 |
+
linkedEditing: true,
|
| 187 |
+
selectionHighlight: true,
|
| 188 |
+
occurrencesHighlight: 'multiFile',
|
| 189 |
+
codeLens: false,
|
| 190 |
+
hover: { enabled: true, delay: 600 },
|
| 191 |
+
'semanticHighlighting.enabled': true,
|
| 192 |
+
overviewRulerLanes: 3,
|
| 193 |
+
unicodeHighlight: { ambiguousCharacters: false },
|
| 194 |
+
stickyScroll: { enabled: true },
|
| 195 |
+
});
|
| 196 |
+
|
| 197 |
+
// ── TS/JS built-in diagnostics (ESLint-like for JS & TS) ──────────────
|
| 198 |
+
var tsCompOpts = {
|
| 199 |
+
target: monaco.languages.typescript.ScriptTarget.ESNext,
|
| 200 |
+
module: monaco.languages.typescript.ModuleKind.ESNext,
|
| 201 |
+
allowJs: true,
|
| 202 |
+
checkJs: true,
|
| 203 |
+
jsx: monaco.languages.typescript.JsxEmit.React,
|
| 204 |
+
noUnusedLocals: true,
|
| 205 |
+
noUnusedParameters: false,
|
| 206 |
+
strict: false,
|
| 207 |
+
allowNonTsExtensions: true,
|
| 208 |
+
};
|
| 209 |
+
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(tsCompOpts);
|
| 210 |
+
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(
|
| 211 |
+
Object.assign({}, tsCompOpts, { strict: true, noUnusedLocals: true })
|
| 212 |
+
);
|
| 213 |
+
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
|
| 214 |
+
noSemanticValidation: false,
|
| 215 |
+
noSyntaxValidation: false,
|
| 216 |
+
diagnosticCodesToIgnore: [2792, 2307], // ignore "cannot find module" warnings
|
| 217 |
+
});
|
| 218 |
+
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
|
| 219 |
+
noSemanticValidation: false,
|
| 220 |
+
noSyntaxValidation: false,
|
| 221 |
+
diagnosticCodesToIgnore: [2792, 2307],
|
| 222 |
+
});
|
| 223 |
+
|
| 224 |
+
// ── Language snippets (custom completions per language) ────────────────
|
| 225 |
+
function makeSnip(label, insertText, docs) {
|
| 226 |
+
return {
|
| 227 |
+
label: label,
|
| 228 |
+
kind: monaco.languages.CompletionItemKind.Snippet,
|
| 229 |
+
documentation: docs || label,
|
| 230 |
+
insertText: insertText,
|
| 231 |
+
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
| 232 |
+
range: undefined,
|
| 233 |
+
};
|
| 234 |
+
}
|
| 235 |
+
var jsSnippets = [
|
| 236 |
+
makeSnip('cl', 'console.log(${1:value});$0', 'console.log'),
|
| 237 |
+
makeSnip('ce', 'console.error(${1:error});$0', 'console.error'),
|
| 238 |
+
makeSnip('fn', 'function ${1:name}(${2:params}) {\n\t$0\n}', 'function'),
|
| 239 |
+
makeSnip('afn', '(${1:params}) => {\n\t$0\n}', 'arrow function'),
|
| 240 |
+
makeSnip('aafn', 'async (${1:params}) => {\n\t$0\n}', 'async arrow function'),
|
| 241 |
+
makeSnip('anfn', 'async function ${1:name}(${2:params}) {\n\t$0\n}', 'async function'),
|
| 242 |
+
makeSnip('imp', "import ${1:thing} from '${2:module}';$0", 'import'),
|
| 243 |
+
makeSnip('imd', "import * as ${1:name} from '${2:module}';$0", 'import *'),
|
| 244 |
+
makeSnip('imn', "import '${1:module}';$0", 'import (side-effect)'),
|
| 245 |
+
makeSnip('req', "const ${1:name} = require('${2:module}');$0", 'require'),
|
| 246 |
+
makeSnip('trycatch', 'try {\n\t${1:// code}\n} catch (${2:err}) {\n\t${3:// handle}\n}$0', 'try/catch'),
|
| 247 |
+
makeSnip('prom', 'new Promise((resolve, reject) => {\n\t$0\n});', 'new Promise'),
|
| 248 |
+
makeSnip('cls', 'class ${1:Name} {\n\tconstructor(${2:params}) {\n\t\t$0\n\t}\n}', 'class'),
|
| 249 |
+
makeSnip('ternary', '${1:cond} ? ${2:then} : ${3:else}', 'ternary'),
|
| 250 |
+
makeSnip('des', 'const { ${1:key} } = ${2:obj};$0', 'destructure object'),
|
| 251 |
+
makeSnip('itar', 'for (let ${1:i} = 0; ${1:i} < ${2:arr}.length; ${1:i}++) {\n\t$0\n}', 'for loop'),
|
| 252 |
+
makeSnip('forof', 'for (const ${1:item} of ${2:iterable}) {\n\t$0\n}', 'for...of'),
|
| 253 |
+
makeSnip('forin', 'for (const ${1:key} in ${2:obj}) {\n\t$0\n}', 'for...in'),
|
| 254 |
+
makeSnip('sw', 'switch (${1:expr}) {\n\tcase ${2:val}:\n\t\t$0\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n}', 'switch'),
|
| 255 |
+
makeSnip('settimeout', 'setTimeout(() => {\n\t$0\n}, ${1:1000});', 'setTimeout'),
|
| 256 |
+
makeSnip('setinterval', 'setInterval(() => {\n\t$0\n}, ${1:1000});', 'setInterval'),
|
| 257 |
+
makeSnip('docid', "document.getElementById('${1:id}')$0", 'getElementById'),
|
| 258 |
+
makeSnip('docqs', "document.querySelector('${1:selector}')$0", 'querySelector'),
|
| 259 |
+
];
|
| 260 |
+
['javascript','javascriptreact','typescript','typescriptreact'].forEach(function(lid) {
|
| 261 |
+
monaco.languages.registerCompletionItemProvider(lid, {
|
| 262 |
+
provideCompletionItems: function(model, pos) {
|
| 263 |
+
var word = model.getWordUntilPosition(pos);
|
| 264 |
+
var range = { startLineNumber: pos.lineNumber, endLineNumber: pos.lineNumber,
|
| 265 |
+
startColumn: word.startColumn, endColumn: word.endColumn };
|
| 266 |
+
return { suggestions: jsSnippets.map(function(s) { return Object.assign({}, s, { range: range }); }) };
|
| 267 |
+
}
|
| 268 |
+
});
|
| 269 |
+
});
|
| 270 |
+
var pySnippets = [
|
| 271 |
+
makeSnip('def', 'def ${1:name}(${2:params}):\n\t${3:pass}$0', 'def'),
|
| 272 |
+
makeSnip('cls', 'class ${1:Name}:\n\tdef __init__(self${2:, params}):\n\t\t${3:pass}$0', 'class'),
|
| 273 |
+
makeSnip('ifmain', "if __name__ == '__main__':\n\t$0", 'if __name__'),
|
| 274 |
+
makeSnip('trycatch','try:\n\t${1:pass}\nexcept ${2:Exception} as e:\n\t${3:pass}$0', 'try/except'),
|
| 275 |
+
makeSnip('wopen', "with open('${1:file}', '${2:r}') as f:\n\t$0", 'with open'),
|
| 276 |
+
makeSnip('lc', '[${1:expr} for ${2:x} in ${3:iterable}]$0', 'list comprehension'),
|
| 277 |
+
makeSnip('dc', '{${1:key}: ${2:val} for ${3:k}, ${4:v} in ${5:dict}.items()}$0', 'dict comprehension'),
|
| 278 |
+
makeSnip('pr', 'print(${1:value})$0', 'print'),
|
| 279 |
+
makeSnip('prf', 'print(f"${1:text}")$0', 'print f-string'),
|
| 280 |
+
makeSnip('impas', 'import ${1:module} as ${2:alias}$0', 'import as'),
|
| 281 |
+
makeSnip('fromimp', 'from ${1:module} import ${2:name}$0', 'from import'),
|
| 282 |
+
makeSnip('lam', 'lambda ${1:params}: ${2:expr}$0', 'lambda'),
|
| 283 |
+
makeSnip('forloop', 'for ${1:item} in ${2:iterable}:\n\t$0', 'for'),
|
| 284 |
+
makeSnip('whileloop','while ${1:True}:\n\t$0', 'while'),
|
| 285 |
+
makeSnip('glb', 'global ${1:var}$0', 'global'),
|
| 286 |
+
];
|
| 287 |
+
monaco.languages.registerCompletionItemProvider('python', {
|
| 288 |
+
provideCompletionItems: function(model, pos) {
|
| 289 |
+
var word = model.getWordUntilPosition(pos);
|
| 290 |
+
var range = { startLineNumber: pos.lineNumber, endLineNumber: pos.lineNumber,
|
| 291 |
+
startColumn: word.startColumn, endColumn: word.endColumn };
|
| 292 |
+
return { suggestions: pySnippets.map(function(s) { return Object.assign({}, s, { range: range }); }) };
|
| 293 |
+
}
|
| 294 |
+
});
|
| 295 |
+
var cssSnippets = [
|
| 296 |
+
makeSnip('flex', 'display: flex;\nalign-items: ${1:center};\njustify-content: ${2:center};$0', 'flexbox center'),
|
| 297 |
+
makeSnip('grid', 'display: grid;\ngrid-template-columns: ${1:repeat(3, 1fr)};\ngap: ${2:1rem};$0', 'grid'),
|
| 298 |
+
makeSnip('abs', 'position: absolute;\ntop: ${1:0};\nleft: ${2:0};$0', 'absolute'),
|
| 299 |
+
makeSnip('tr', 'transition: ${1:all} ${2:0.3s} ${3:ease};$0', 'transition'),
|
| 300 |
+
makeSnip('shadow', 'box-shadow: ${1:0 4px 6px} rgba(0,0,0,${2:0.1});$0', 'box-shadow'),
|
| 301 |
+
makeSnip('size', 'width: ${1};\nheight: ${2};$0', 'width+height'),
|
| 302 |
+
makeSnip('media', '@media (max-width: ${1:768px}) {\n\t$0\n}', '@media'),
|
| 303 |
+
makeSnip('var', 'var(--${1:name})$0', 'CSS variable'),
|
| 304 |
+
makeSnip('mixin', '@mixin ${1:name}(${2:params}) {\n\t$0\n}', '@mixin (SCSS)'),
|
| 305 |
+
];
|
| 306 |
+
['css','scss','less'].forEach(function(lid) {
|
| 307 |
+
monaco.languages.registerCompletionItemProvider(lid, {
|
| 308 |
+
provideCompletionItems: function(model, pos) {
|
| 309 |
+
var word = model.getWordUntilPosition(pos);
|
| 310 |
+
var range = { startLineNumber: pos.lineNumber, endLineNumber: pos.lineNumber,
|
| 311 |
+
startColumn: word.startColumn, endColumn: word.endColumn };
|
| 312 |
+
return { suggestions: cssSnippets.map(function(s) { return Object.assign({}, s, { range: range }); }) };
|
| 313 |
+
}
|
| 314 |
+
});
|
| 315 |
+
});
|
| 316 |
+
|
| 317 |
+
// ── Cursor position → broadcast to RN (status bar) ────────────────────
|
| 318 |
+
editor.onDidChangeCursorSelection(function(e) {
|
| 319 |
+
var pos = editor.getPosition();
|
| 320 |
+
var sel = editor.getSelection();
|
| 321 |
+
var selLen = 0;
|
| 322 |
+
if (sel && !sel.isEmpty()) {
|
| 323 |
+
selLen = editor.getModel().getValueInRange(sel).length;
|
| 324 |
+
}
|
| 325 |
+
postToRN({ type: 'cursor', line: pos.lineNumber, col: pos.column, sel: selLen });
|
| 326 |
+
});
|
| 327 |
+
|
| 328 |
+
// ── TODO / FIXME / HACK / BUG / NOTE highlight decorations ────────────
|
| 329 |
+
function refreshTodo() {
|
| 330 |
+
if (!editor) return;
|
| 331 |
+
var model = editor.getModel();
|
| 332 |
+
if (!model) return;
|
| 333 |
+
clearTimeout(todoDebounce);
|
| 334 |
+
todoDebounce = setTimeout(function () {
|
| 335 |
+
var content = model.getValue();
|
| 336 |
+
var decs = [];
|
| 337 |
+
var re = /\b(TODO|FIXME|HACK|BUG|NOTE|XXX)\b[^\n]*/g;
|
| 338 |
+
var match;
|
| 339 |
+
while ((match = re.exec(content)) !== null) {
|
| 340 |
+
var startPos = model.getPositionAt(match.index);
|
| 341 |
+
var endPos = model.getPositionAt(match.index + match[0].length);
|
| 342 |
+
var kw = match[1];
|
| 343 |
+
var cls = /FIXME|BUG/.test(kw) ? 'td-fixme' : /NOTE|HACK/.test(kw) ? 'td-note' : 'td-todo';
|
| 344 |
+
var ovColor = /FIXME|BUG/.test(kw) ? '#f87171' : /NOTE|HACK/.test(kw) ? '#38bdf8' : '#fbbf24';
|
| 345 |
+
decs.push({
|
| 346 |
+
range: {
|
| 347 |
+
startLineNumber: startPos.lineNumber, startColumn: startPos.column,
|
| 348 |
+
endLineNumber: endPos.lineNumber, endColumn: endPos.column,
|
| 349 |
+
},
|
| 350 |
+
options: {
|
| 351 |
+
inlineClassName: cls,
|
| 352 |
+
overviewRuler: { color: ovColor, position: monaco.editor.OverviewRulerLane.Right },
|
| 353 |
+
stickiness: 1,
|
| 354 |
+
}
|
| 355 |
+
});
|
| 356 |
+
}
|
| 357 |
+
todoIds = editor.deltaDecorations(todoIds, decs);
|
| 358 |
+
}, 600);
|
| 359 |
+
}
|
| 360 |
+
editor.onDidChangeModelContent(refreshTodo);
|
| 361 |
+
|
| 362 |
+
// ── Emmet for HTML / CSS (lazy CDN) ───────────────────────────────────
|
| 363 |
+
function loadEmmet(cb) {
|
| 364 |
+
if (emmetReady) { if (cb) cb(); return; }
|
| 365 |
+
if (emmetLoading) return;
|
| 366 |
+
emmetLoading = true;
|
| 367 |
+
var s = document.createElement('script');
|
| 368 |
+
s.src = 'https://cdn.jsdelivr.net/npm/emmet-monaco-es@5.3.1/dist/emmet-monaco.min.js';
|
| 369 |
+
s.onload = function () {
|
| 370 |
+
try {
|
| 371 |
+
if (window.emmetMonaco)
|
| 372 |
+
window.emmetMonaco.emmetHTML(monaco, ['html','xml','php','jsx','tsx','vue','handlebars']);
|
| 373 |
+
} catch(e) {}
|
| 374 |
+
emmetReady = true;
|
| 375 |
+
if (cb) cb();
|
| 376 |
+
};
|
| 377 |
+
s.onerror = function () { emmetLoading = false; };
|
| 378 |
+
document.head.appendChild(s);
|
| 379 |
+
}
|
| 380 |
+
// Pre-load Emmet in the background after editor is ready
|
| 381 |
+
setTimeout(loadEmmet, 2000);
|
| 382 |
+
|
| 383 |
+
// ── Error Lens ─────────────────────────────────────────────────────────
|
| 384 |
+
function refreshErrorLens() {
|
| 385 |
+
if (!editor) return;
|
| 386 |
+
var model = editor.getModel();
|
| 387 |
+
if (!model) return;
|
| 388 |
+
var markers = monaco.editor.getModelMarkers({ resource: model.uri });
|
| 389 |
+
var decs = markers
|
| 390 |
+
.filter(function (m) { return m.severity >= 4; })
|
| 391 |
+
.map(function (m) {
|
| 392 |
+
var cls = m.severity === 8 ? 'el-error' : m.severity === 4 ? 'el-warn' : 'el-info';
|
| 393 |
+
var icon = m.severity === 8 ? '✖ ' : m.severity === 4 ? '⚠ ' : 'ℹ ';
|
| 394 |
+
var txt = m.message.replace(/[\r\n]+/g, ' ').slice(0, 80);
|
| 395 |
+
return {
|
| 396 |
+
range: {
|
| 397 |
+
startLineNumber: m.endLineNumber,
|
| 398 |
+
startColumn: model.getLineMaxColumn(m.endLineNumber),
|
| 399 |
+
endLineNumber: m.endLineNumber,
|
| 400 |
+
endColumn: model.getLineMaxColumn(m.endLineNumber),
|
| 401 |
+
},
|
| 402 |
+
options: {
|
| 403 |
+
after: { content: ' ' + icon + txt, inlineClassName: cls },
|
| 404 |
+
stickiness: 1,
|
| 405 |
+
}
|
| 406 |
+
};
|
| 407 |
+
});
|
| 408 |
+
errorLensIds = editor.deltaDecorations(errorLensIds, decs);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
monaco.editor.onDidChangeMarkers(function (uris) {
|
| 412 |
+
if (!editor) return;
|
| 413 |
+
var m = editor.getModel();
|
| 414 |
+
if (!m) return;
|
| 415 |
+
var me = m.uri.toString();
|
| 416 |
+
if (uris.some(function (u) { return u.toString() === me; })) refreshErrorLens();
|
| 417 |
+
});
|
| 418 |
+
|
| 419 |
+
// ── Content change → notify RN ────────────────────────────────────────
|
| 420 |
+
editor.onDidChangeModelContent(function () {
|
| 421 |
+
postToRN({ type: 'contentChanged', isDirty: true });
|
| 422 |
+
});
|
| 423 |
+
// ── Pinch-to-zoom + Two-finger swipe Undo/Redo ────────────────────────
|
| 424 |
+
// DISABLED: custom touch listeners were blocking native WebView scroll.
|
| 425 |
+
// Re-enable only after native scroll is confirmed working.
|
| 426 |
+
/*
|
| 427 |
+
var t2 = { on: false, startD: 0, startFS: 15, startY: 0, didPinch: false };
|
| 428 |
+
|
| 429 |
+
function fingerDist(e) {
|
| 430 |
+
var dx = e.touches[1].clientX - e.touches[0].clientX;
|
| 431 |
+
var dy = e.touches[1].clientY - e.touches[0].clientY;
|
| 432 |
+
return Math.sqrt(dx * dx + dy * dy);
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
document.addEventListener('touchstart', function (e) {
|
| 436 |
+
if (e.touches.length === 2) {
|
| 437 |
+
t2.on = true; t2.didPinch = false;
|
| 438 |
+
t2.startD = fingerDist(e);
|
| 439 |
+
t2.startFS = currentFontSize;
|
| 440 |
+
t2.startY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
|
| 441 |
+
} else { t2.on = false; }
|
| 442 |
+
}, { passive: true });
|
| 443 |
+
|
| 444 |
+
document.addEventListener('touchmove', function (e) {
|
| 445 |
+
if (!t2.on || e.touches.length < 2) return;
|
| 446 |
+
var ratio = fingerDist(e) / t2.startD;
|
| 447 |
+
if (Math.abs(ratio - 1) > 0.12) {
|
| 448 |
+
t2.didPinch = true;
|
| 449 |
+
var ns = Math.round(Math.max(10, Math.min(32, t2.startFS * ratio)));
|
| 450 |
+
if (ns !== currentFontSize) {
|
| 451 |
+
currentFontSize = ns;
|
| 452 |
+
editor.updateOptions({ fontSize: ns });
|
| 453 |
+
postToRN({ type: 'fontSizeChanged', size: ns });
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
}, { passive: true });
|
| 457 |
+
|
| 458 |
+
document.addEventListener('touchend', function (e) {
|
| 459 |
+
if (t2.on && !t2.didPinch && e.changedTouches.length > 0) {
|
| 460 |
+
var dy = e.changedTouches[0].clientY - t2.startY;
|
| 461 |
+
if (Math.abs(dy) > 50) {
|
| 462 |
+
if (dy > 0) { editor.trigger('kb', 'undo', null); postToRN({ type: 'undo' }); }
|
| 463 |
+
else { editor.trigger('kb', 'redo', null); postToRN({ type: 'redo' }); }
|
| 464 |
+
}
|
| 465 |
+
}
|
| 466 |
+
t2.on = false;
|
| 467 |
+
}, { passive: true });
|
| 468 |
+
|
| 469 |
+
document.getElementById('editor-container').addEventListener('touchend', function () {
|
| 470 |
+
editor.focus();
|
| 471 |
+
}, { passive: true });
|
| 472 |
+
*/
|
| 473 |
+
|
| 474 |
+
window.__focusKeyboard = function() {
|
| 475 |
+
editor.focus();
|
| 476 |
+
var inputArea = document.querySelector('textarea.inputarea');
|
| 477 |
+
if (inputArea) inputArea.focus();
|
| 478 |
+
};
|
| 479 |
+
|
| 480 |
+
// Keep textarea focused when user taps editor text area (no custom touch interception).
|
| 481 |
+
editor.onDidFocusEditorText(function () {
|
| 482 |
+
if (window.__focusKeyboard) window.__focusKeyboard();
|
| 483 |
+
});
|
| 484 |
+
|
| 485 |
+
postToRN({ type: 'ready' });
|
| 486 |
+
}); // end require
|
| 487 |
+
|
| 488 |
+
// ─── Prettier (lazy load from CDN) ────────────────────────────────────────
|
| 489 |
+
var PV = '2.8.8';
|
| 490 |
+
function loadPrettier(cb) {
|
| 491 |
+
if (prettierReady) { cb(); return; }
|
| 492 |
+
if (prettierLoading) {
|
| 493 |
+
var ti = setInterval(function () { if (prettierReady) { clearInterval(ti); cb(); } }, 300);
|
| 494 |
+
return;
|
| 495 |
+
}
|
| 496 |
+
prettierLoading = true;
|
| 497 |
+
var srcs = [
|
| 498 |
+
'standalone', 'parser-babel', 'parser-typescript',
|
| 499 |
+
'parser-html', 'parser-postcss', 'parser-markdown',
|
| 500 |
+
'parser-yaml', 'parser-graphql', 'parser-angular',
|
| 501 |
+
].map(function (n) { return 'https://cdn.jsdelivr.net/npm/prettier@' + PV + '/' + n + '.js'; });
|
| 502 |
+
var done = 0;
|
| 503 |
+
srcs.forEach(function (src) {
|
| 504 |
+
var s = document.createElement('script');
|
| 505 |
+
s.src = src; s.async = false;
|
| 506 |
+
s.onload = s.onerror = function () { if (++done === srcs.length) { prettierReady = true; cb(); } };
|
| 507 |
+
document.head.appendChild(s);
|
| 508 |
+
});
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
function runPrettier(content, lang, cb) {
|
| 512 |
+
loadPrettier(function () {
|
| 513 |
+
if (!window.prettier || !window.prettierPlugins) { cb(null); return; }
|
| 514 |
+
var pm = {
|
| 515 |
+
javascript: 'babel', javascriptreact: 'babel',
|
| 516 |
+
typescript: 'typescript', typescriptreact: 'typescript',
|
| 517 |
+
html: 'html', css: 'css', scss: 'scss', less: 'less',
|
| 518 |
+
json: 'json', markdown: 'markdown', yaml: 'yaml',
|
| 519 |
+
graphql: 'graphql', vue: 'vue', angular: 'angular',
|
| 520 |
+
};
|
| 521 |
+
var parser = pm[lang];
|
| 522 |
+
if (!parser) { cb(null); return; }
|
| 523 |
+
var p = window.prettierPlugins;
|
| 524 |
+
var plugins = [p.babel, p.typescript, p.html, p.postcss, p.markdown, p.yaml, p.graphql, p.angular].filter(Boolean);
|
| 525 |
+
try {
|
| 526 |
+
cb(window.prettier.format(content, {
|
| 527 |
+
parser: parser, plugins: plugins,
|
| 528 |
+
printWidth: 80, tabWidth: 2, semi: true,
|
| 529 |
+
singleQuote: true, trailingComma: 'es5',
|
| 530 |
+
bracketSpacing: true, arrowParens: 'avoid', endOfLine: 'lf',
|
| 531 |
+
}));
|
| 532 |
+
} catch (e) { cb(null); }
|
| 533 |
+
});
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
// ─── Command bus ──────────────────────────────────────────────────────────
|
| 537 |
+
function onMsg(e) { try { run(JSON.parse(e.data)); } catch (_) {} }
|
| 538 |
+
window.addEventListener('message', onMsg);
|
| 539 |
+
document.addEventListener('message', onMsg);
|
| 540 |
+
|
| 541 |
+
function run(msg) {
|
| 542 |
+
if (!editor) return;
|
| 543 |
+
var model = editor.getModel();
|
| 544 |
+
switch (msg.type) {
|
| 545 |
+
|
| 546 |
+
case 'setContent':
|
| 547 |
+
editor.setValue(msg.content || '');
|
| 548 |
+
if (msg.language && model) {
|
| 549 |
+
monaco.editor.setModelLanguage(model, msg.language);
|
| 550 |
+
// Enable JS/TS diagnostics ONLY for JS/TS files — everything else gets no false errors
|
| 551 |
+
var _isJsTs = ['javascript','javascriptreact','typescript','typescriptreact'].indexOf(msg.language) !== -1;
|
| 552 |
+
var _diagOn = { noSemanticValidation: !_isJsTs, noSyntaxValidation: !_isJsTs, diagnosticCodesToIgnore: [2792, 2307] };
|
| 553 |
+
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions(_diagOn);
|
| 554 |
+
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions(_diagOn);
|
| 555 |
+
}
|
| 556 |
+
editor.setScrollPosition({ scrollTop: 0, scrollLeft: 0 });
|
| 557 |
+
refreshTodo();
|
| 558 |
+
break;
|
| 559 |
+
|
| 560 |
+
case 'getContent':
|
| 561 |
+
postToRN({ type: 'content', content: editor.getValue() });
|
| 562 |
+
break;
|
| 563 |
+
|
| 564 |
+
case 'setLanguage':
|
| 565 |
+
model && monaco.editor.setModelLanguage(model, msg.language);
|
| 566 |
+
break;
|
| 567 |
+
|
| 568 |
+
case 'undo': editor.trigger('kb', 'undo', null); break;
|
| 569 |
+
case 'redo': editor.trigger('kb', 'redo', null); break;
|
| 570 |
+
|
| 571 |
+
case 'find':
|
| 572 |
+
(editor.getAction('actions.find') || editor.getAction('editor.action.findWithArgs')).run();
|
| 573 |
+
break;
|
| 574 |
+
|
| 575 |
+
case 'format': {
|
| 576 |
+
var lang = model ? model.getLanguageId() : 'plaintext';
|
| 577 |
+
var src = editor.getValue();
|
| 578 |
+
runPrettier(src, lang, function (r) {
|
| 579 |
+
if (r && r !== src) {
|
| 580 |
+
var pos = editor.getPosition();
|
| 581 |
+
editor.setValue(r);
|
| 582 |
+
pos && editor.setPosition(pos);
|
| 583 |
+
} else {
|
| 584 |
+
var a = editor.getAction('editor.action.formatDocument');
|
| 585 |
+
a && a.run();
|
| 586 |
+
}
|
| 587 |
+
});
|
| 588 |
+
break;
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
case 'fontSize': {
|
| 592 |
+
var next = msg.delta !== undefined ? currentFontSize + msg.delta : (msg.size || currentFontSize);
|
| 593 |
+
currentFontSize = Math.max(10, Math.min(32, Math.round(next)));
|
| 594 |
+
editor.updateOptions({ fontSize: currentFontSize });
|
| 595 |
+
postToRN({ type: 'fontSizeChanged', size: currentFontSize });
|
| 596 |
+
break;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
case 'toggleWordWrap':
|
| 600 |
+
wordWrapEnabled = !wordWrapEnabled;
|
| 601 |
+
editor.updateOptions({ wordWrap: wordWrapEnabled ? 'on' : 'off' });
|
| 602 |
+
postToRN({ type: 'wordWrapChanged', enabled: wordWrapEnabled });
|
| 603 |
+
break;
|
| 604 |
+
|
| 605 |
+
case 'wordWrap':
|
| 606 |
+
wordWrapEnabled = !!msg.enabled;
|
| 607 |
+
editor.updateOptions({ wordWrap: wordWrapEnabled ? 'on' : 'off' });
|
| 608 |
+
break;
|
| 609 |
+
|
| 610 |
+
case 'insertText': {
|
| 611 |
+
var t = msg.text;
|
| 612 |
+
if (t === '⇥') editor.trigger('kb', 'editor.action.indentLines', null);
|
| 613 |
+
else if (t === '⇤') editor.trigger('kb', 'editor.action.outdentLines', null);
|
| 614 |
+
else if (t === '←') editor.trigger('kb', 'cursorLeft', null);
|
| 615 |
+
else if (t === '→') editor.trigger('kb', 'cursorRight', null);
|
| 616 |
+
else if (t === '↑') editor.trigger('kb', 'cursorUp', null);
|
| 617 |
+
else if (t === '↓') editor.trigger('kb', 'cursorDown', null);
|
| 618 |
+
else {
|
| 619 |
+
editor.executeEdits('snip', [{ range: editor.getSelection(), text: t, forceMoveMarkers: true }]);
|
| 620 |
+
editor.focus();
|
| 621 |
+
}
|
| 622 |
+
break;
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
case 'duplicateLine':
|
| 626 |
+
editor.trigger('kb', 'editor.action.copyLinesDownAction', null);
|
| 627 |
+
break;
|
| 628 |
+
|
| 629 |
+
case 'toggleComment':
|
| 630 |
+
editor.trigger('kb', 'editor.action.commentLine', null);
|
| 631 |
+
break;
|
| 632 |
+
|
| 633 |
+
case 'lineUp':
|
| 634 |
+
editor.trigger('kb', 'editor.action.moveLinesUpAction', null);
|
| 635 |
+
break;
|
| 636 |
+
|
| 637 |
+
case 'lineDown':
|
| 638 |
+
editor.trigger('kb', 'editor.action.moveLinesDownAction', null);
|
| 639 |
+
break;
|
| 640 |
+
|
| 641 |
+
case 'toggleMinimap': {
|
| 642 |
+
var cur = editor.getOption(monaco.editor.EditorOption.minimap);
|
| 643 |
+
editor.updateOptions({ minimap: { enabled: !cur.enabled } });
|
| 644 |
+
postToRN({ type: 'minimapChanged', enabled: !cur.enabled });
|
| 645 |
+
break;
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
case 'focusKeyboard':
|
| 649 |
+
if (window.__focusKeyboard) window.__focusKeyboard();
|
| 650 |
+
break;
|
| 651 |
+
|
| 652 |
+
case 'markClean': break;
|
| 653 |
+
}
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
function postToRN(obj) {
|
| 657 |
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify(obj));
|
| 658 |
+
}
|
| 659 |
+
})();
|
| 660 |
+
</script>
|
| 661 |
+
</body>
|
| 662 |
+
</html>
|
babel.config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function (api) {
|
| 2 |
+
api.cache(true);
|
| 3 |
+
return {
|
| 4 |
+
presets: ['babel-preset-expo'],
|
| 5 |
+
plugins: ['react-native-reanimated/plugin'],
|
| 6 |
+
};
|
| 7 |
+
};
|
dev-commands.bat
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
chcp 65001 >nul
|
| 3 |
+
setlocal enabledelayedexpansion
|
| 4 |
+
|
| 5 |
+
:: ── ตั้ง PROJECT_ROOT = folder ที่ bat ไฟล์นี้อยู่ (ลบ \ ท้าย) ──────────────
|
| 6 |
+
set "PROJECT_ROOT=%~dp0"
|
| 7 |
+
if "%PROJECT_ROOT:~-1%"=="\" set "PROJECT_ROOT=%PROJECT_ROOT:~0,-1%"
|
| 8 |
+
|
| 9 |
+
:MENU
|
| 10 |
+
cls
|
| 11 |
+
echo ╔══════════════════════════════════════════════════════════════╗
|
| 12 |
+
echo ║ EXPO / REACT NATIVE ANDROID - DEV COMMANDS ║
|
| 13 |
+
echo ║ Project: %PROJECT_ROOT%
|
| 14 |
+
echo ╚══════════════════════════════════════════════════════════════╝
|
| 15 |
+
echo.
|
| 16 |
+
echo ── INSTALL TO PHONE (มือถือต้องต่ออยู่) ─────────────────────
|
| 17 |
+
echo [1] installDebug ← ใช้ทดสอบ (แนะนำ)
|
| 18 |
+
echo [2] installRelease ← ใช้แจกจ่าย
|
| 19 |
+
echo.
|
| 20 |
+
echo ── BUILD APK FILE (ไม่ต้องต่อมือถือ) ───────────────────────
|
| 21 |
+
echo [3] assembleDebug → apk\debug\app-debug.apk
|
| 22 |
+
echo [4] assembleRelease → apk\release\chahuadev-code-editor.apk
|
| 23 |
+
echo.
|
| 24 |
+
echo ── EXPO / METRO ─────────────────────────────────────────────
|
| 25 |
+
echo [5] expo start ← Metro + QR code (dev mode)
|
| 26 |
+
echo [6] expo run:android ← Metro + auto install (ต่อมือถือ)
|
| 27 |
+
echo [7] expo prebuild ← สร้าง/อัปเดต /android folder
|
| 28 |
+
echo.
|
| 29 |
+
echo ── NPM ──────────────────────────────────────────────────────
|
| 30 |
+
echo [8] npm install
|
| 31 |
+
echo [9] npm install --legacy-peer-deps
|
| 32 |
+
echo.
|
| 33 |
+
echo ── CLEAN BUILD ──────────────────────────────────────────────
|
| 34 |
+
echo [10] clean ← ล้าง gradle cache
|
| 35 |
+
echo [11] clean + installDebug ← clean แล้ว build ใหม่ทั้งหมด
|
| 36 |
+
echo.
|
| 37 |
+
echo ── OPEN FOLDER ──────────────────────────────────────────────
|
| 38 |
+
echo [12] เปิด folder APK output
|
| 39 |
+
echo [13] เปิด project ใน Explorer
|
| 40 |
+
echo.
|
| 41 |
+
echo ── ADB (Android Debug Bridge) ───────────────────────────────
|
| 42 |
+
echo [14] adb devices ← ตรวจมือถือต่อหรือเปล่า
|
| 43 |
+
echo [15] adb logcat ← ดู log จากมือถือ (Ctrl+C หยุด)
|
| 44 |
+
echo [16] adb logcat ^| findstr "ReactNative^|ERROR^|WARN" ← log เฉพาะ RN
|
| 45 |
+
echo [17] adb install APK ← install APK ที่ build ไว้แล้ว
|
| 46 |
+
echo [18] adb uninstall app ← ถอนการติดตั้ง
|
| 47 |
+
echo.
|
| 48 |
+
echo [0] ออก
|
| 49 |
+
echo.
|
| 50 |
+
set /p choice=เลือกหมายเลข:
|
| 51 |
+
|
| 52 |
+
if "%choice%"=="1" goto DO_INSTALL_DEBUG
|
| 53 |
+
if "%choice%"=="2" goto DO_INSTALL_RELEASE
|
| 54 |
+
if "%choice%"=="3" goto DO_ASSEMBLE_DEBUG
|
| 55 |
+
if "%choice%"=="4" goto DO_ASSEMBLE_RELEASE
|
| 56 |
+
if "%choice%"=="5" goto DO_EXPO_START
|
| 57 |
+
if "%choice%"=="6" goto DO_EXPO_RUN
|
| 58 |
+
if "%choice%"=="7" goto DO_EXPO_PREBUILD
|
| 59 |
+
if "%choice%"=="8" goto DO_NPM_INSTALL
|
| 60 |
+
if "%choice%"=="9" goto DO_NPM_INSTALL_LEGACY
|
| 61 |
+
if "%choice%"=="10" goto DO_CLEAN
|
| 62 |
+
if "%choice%"=="11" goto DO_CLEAN_DEBUG
|
| 63 |
+
if "%choice%"=="12" goto DO_OPEN_APK
|
| 64 |
+
if "%choice%"=="13" goto DO_OPEN_PROJECT
|
| 65 |
+
if "%choice%"=="14" goto DO_ADB_DEVICES
|
| 66 |
+
if "%choice%"=="15" goto DO_ADB_LOGCAT
|
| 67 |
+
if "%choice%"=="16" goto DO_ADB_LOGCAT_RN
|
| 68 |
+
if "%choice%"=="17" goto DO_ADB_INSTALL
|
| 69 |
+
if "%choice%"=="18" goto DO_ADB_UNINSTALL
|
| 70 |
+
if "%choice%"=="0" goto END
|
| 71 |
+
goto MENU
|
| 72 |
+
|
| 73 |
+
:DO_INSTALL_DEBUG
|
| 74 |
+
echo.
|
| 75 |
+
echo [installDebug] กำลัง build debug + ติดตั้งลงมือถือ...
|
| 76 |
+
echo คำสั่ง: %PROJECT_ROOT%\android\gradlew.bat app:installDebug --daemon
|
| 77 |
+
cd /d "%PROJECT_ROOT%\android"
|
| 78 |
+
call gradlew.bat app:installDebug --daemon
|
| 79 |
+
echo.
|
| 80 |
+
echo เสร็จแล้ว! กด Enter กลับเมนู
|
| 81 |
+
pause >nul
|
| 82 |
+
goto MENU
|
| 83 |
+
|
| 84 |
+
:DO_INSTALL_RELEASE
|
| 85 |
+
echo.
|
| 86 |
+
echo [installRelease] กำลัง build release + ติดตั้งลงมือถือ...
|
| 87 |
+
echo คำสั่ง: %PROJECT_ROOT%\android\gradlew.bat app:installRelease --daemon
|
| 88 |
+
cd /d "%PROJECT_ROOT%\android"
|
| 89 |
+
call gradlew.bat app:installRelease --daemon
|
| 90 |
+
echo.
|
| 91 |
+
echo เสร็จแล้ว! กด Enter กลับเมนู
|
| 92 |
+
pause >nul
|
| 93 |
+
goto MENU
|
| 94 |
+
|
| 95 |
+
:DO_ASSEMBLE_DEBUG
|
| 96 |
+
echo.
|
| 97 |
+
echo [assembleDebug] กำลัง build debug APK...
|
| 98 |
+
echo คำสั่ง: %PROJECT_ROOT%\android\gradlew.bat app:assembleDebug --daemon
|
| 99 |
+
cd /d "%PROJECT_ROOT%\android"
|
| 100 |
+
call gradlew.bat app:assembleDebug --daemon
|
| 101 |
+
echo.
|
| 102 |
+
echo ไฟล์อยู่ที่: android\app\build\outputs\apk\debug\
|
| 103 |
+
echo กด Enter กลับเมนู
|
| 104 |
+
pause >nul
|
| 105 |
+
goto MENU
|
| 106 |
+
|
| 107 |
+
:DO_ASSEMBLE_RELEASE
|
| 108 |
+
echo.
|
| 109 |
+
echo [assembleRelease] กำลัง build release APK...
|
| 110 |
+
echo คำสั่ง: %PROJECT_ROOT%\android\gradlew.bat app:assembleRelease --daemon
|
| 111 |
+
cd /d "%PROJECT_ROOT%\android"
|
| 112 |
+
call gradlew.bat app:assembleRelease --daemon
|
| 113 |
+
echo.
|
| 114 |
+
echo ไฟล์อยู่ที่: android\app\build\outputs\apk\release\
|
| 115 |
+
echo กด Enter กลับเมนู
|
| 116 |
+
pause >nul
|
| 117 |
+
goto MENU
|
| 118 |
+
|
| 119 |
+
:DO_EXPO_START
|
| 120 |
+
echo.
|
| 121 |
+
echo [expo start] เปิด Metro bundler + QR code...
|
| 122 |
+
echo กำลัง adb reverse ก่อน (สำหรับ USB)...
|
| 123 |
+
adb reverse tcp:8081 tcp:8081
|
| 124 |
+
echo คำสั่ง: npx expo start
|
| 125 |
+
cd /d "%PROJECT_ROOT%"
|
| 126 |
+
npx expo start
|
| 127 |
+
goto MENU
|
| 128 |
+
|
| 129 |
+
:DO_EXPO_RUN
|
| 130 |
+
echo.
|
| 131 |
+
echo [expo run:android] build + เปิด Metro + install ลงมือถือ...
|
| 132 |
+
echo คำสั่ง: npx expo run:android
|
| 133 |
+
cd /d "%PROJECT_ROOT%"
|
| 134 |
+
npx expo run:android
|
| 135 |
+
goto MENU
|
| 136 |
+
|
| 137 |
+
:DO_EXPO_PREBUILD
|
| 138 |
+
echo.
|
| 139 |
+
echo [expo prebuild] สร้าง/อัปเดต /android native folder...
|
| 140 |
+
echo คำสั่ง: npx expo prebuild --platform android
|
| 141 |
+
cd /d "%PROJECT_ROOT%"
|
| 142 |
+
npx expo prebuild --platform android
|
| 143 |
+
echo.
|
| 144 |
+
echo กด Enter กลับเมนู
|
| 145 |
+
pause >nul
|
| 146 |
+
goto MENU
|
| 147 |
+
|
| 148 |
+
:DO_NPM_INSTALL
|
| 149 |
+
echo.
|
| 150 |
+
echo [npm install] ติดตั้ง dependencies...
|
| 151 |
+
cd /d "%PROJECT_ROOT%"
|
| 152 |
+
npm install
|
| 153 |
+
echo.
|
| 154 |
+
echo กด Enter กลับเมนู
|
| 155 |
+
pause >nul
|
| 156 |
+
goto MENU
|
| 157 |
+
|
| 158 |
+
:DO_NPM_INSTALL_LEGACY
|
| 159 |
+
echo.
|
| 160 |
+
echo [npm install --legacy-peer-deps] ใช้เมื่อมี peer dependency conflict...
|
| 161 |
+
cd /d "%PROJECT_ROOT%"
|
| 162 |
+
npm install --legacy-peer-deps
|
| 163 |
+
echo.
|
| 164 |
+
echo กด Enter กลับเมนู
|
| 165 |
+
pause >nul
|
| 166 |
+
goto MENU
|
| 167 |
+
|
| 168 |
+
:DO_CLEAN
|
| 169 |
+
echo.
|
| 170 |
+
echo [clean] ล้าง gradle build cache...
|
| 171 |
+
cd /d "%PROJECT_ROOT%\android"
|
| 172 |
+
call gradlew.bat clean
|
| 173 |
+
echo.
|
| 174 |
+
echo กด Enter กลับเมนู
|
| 175 |
+
pause >nul
|
| 176 |
+
goto MENU
|
| 177 |
+
|
| 178 |
+
:DO_CLEAN_DEBUG
|
| 179 |
+
echo.
|
| 180 |
+
echo [clean + installDebug] ล้าง cache แล้ว build ใหม่ทั้งหมด...
|
| 181 |
+
cd /d "%PROJECT_ROOT%\android"
|
| 182 |
+
call gradlew.bat clean app:installDebug --daemon
|
| 183 |
+
echo.
|
| 184 |
+
echo กด Enter กลับเมนู
|
| 185 |
+
pause >nul
|
| 186 |
+
goto MENU
|
| 187 |
+
|
| 188 |
+
:DO_OPEN_APK
|
| 189 |
+
echo.
|
| 190 |
+
echo เปิด folder APK output...
|
| 191 |
+
start "" "%PROJECT_ROOT%\android\app\build\outputs\apk"
|
| 192 |
+
goto MENU
|
| 193 |
+
|
| 194 |
+
:DO_OPEN_PROJECT
|
| 195 |
+
echo.
|
| 196 |
+
echo เปิด project folder...
|
| 197 |
+
start "" "%PROJECT_ROOT%"
|
| 198 |
+
goto MENU
|
| 199 |
+
|
| 200 |
+
:DO_ADB_DEVICES
|
| 201 |
+
echo.
|
| 202 |
+
adb devices
|
| 203 |
+
echo.
|
| 204 |
+
echo กด Enter กลับเมนู
|
| 205 |
+
pause >nul
|
| 206 |
+
goto MENU
|
| 207 |
+
|
| 208 |
+
:DO_ADB_LOGCAT
|
| 209 |
+
echo.
|
| 210 |
+
echo [adb logcat] กด Ctrl+C เพื่อหยุด
|
| 211 |
+
adb logcat
|
| 212 |
+
goto MENU
|
| 213 |
+
|
| 214 |
+
:DO_ADB_LOGCAT_RN
|
| 215 |
+
echo.
|
| 216 |
+
echo [adb logcat - React Native only] กด Ctrl+C เพื่อหยุด
|
| 217 |
+
adb logcat | findstr "ReactNative|RN|ERROR|WARN|JSLog"
|
| 218 |
+
goto MENU
|
| 219 |
+
|
| 220 |
+
:DO_ADB_INSTALL
|
| 221 |
+
echo.
|
| 222 |
+
set APK_DEBUG=%PROJECT_ROOT%\android\app\build\outputs\apk\debug\app-debug.apk
|
| 223 |
+
:: หา release APK อัตโนมัติ (ชื่อไฟล์อาจต่างกันแต่ละ project)
|
| 224 |
+
set APK_RELEASE=
|
| 225 |
+
for /f "usebackq delims=" %%f in (`dir /b "%PROJECT_ROOT%\android\app\build\outputs\apk\release\*.apk" 2^>nul`) do (
|
| 226 |
+
if "!APK_RELEASE!"=="" set "APK_RELEASE=%PROJECT_ROOT%\android\app\build\outputs\apk\release\%%f"
|
| 227 |
+
)
|
| 228 |
+
if "!APK_RELEASE!"=="" set "APK_RELEASE=%PROJECT_ROOT%\android\app\build\outputs\apk\release\app-release.apk"
|
| 229 |
+
echo [1] Debug APK
|
| 230 |
+
echo [2] Release APK (!APK_RELEASE!)
|
| 231 |
+
set /p apk_choice=เลือก:
|
| 232 |
+
if "%apk_choice%"=="1" (
|
| 233 |
+
echo adb install "%APK_DEBUG%"
|
| 234 |
+
adb install "%APK_DEBUG%"
|
| 235 |
+
)
|
| 236 |
+
if "%apk_choice%"=="2" (
|
| 237 |
+
echo adb install "!APK_RELEASE!"
|
| 238 |
+
adb install "!APK_RELEASE!"
|
| 239 |
+
)
|
| 240 |
+
echo.
|
| 241 |
+
echo กด Enter กลับเมนู
|
| 242 |
+
pause >nul
|
| 243 |
+
goto MENU
|
| 244 |
+
|
| 245 |
+
:DO_ADB_UNINSTALL
|
| 246 |
+
echo.
|
| 247 |
+
:: อ่าน applicationId จาก android/app/build.gradle อัตโนมัติ
|
| 248 |
+
set APP_PKG=
|
| 249 |
+
for /f "tokens=2 delims= '" %%i in ('findstr /i "applicationId" "%PROJECT_ROOT%\android\app\build.gradle" 2^>nul') do (
|
| 250 |
+
if "!APP_PKG!"=="" set "APP_PKG=%%i"
|
| 251 |
+
)
|
| 252 |
+
set APP_PKG=!APP_PKG:"=!
|
| 253 |
+
set APP_PKG=!APP_PKG: =!
|
| 254 |
+
if "!APP_PKG!"=="" (
|
| 255 |
+
set /p APP_PKG=ไม่พบ applicationId อัตโนมัติ กรุณากรอก package name:
|
| 256 |
+
)
|
| 257 |
+
echo adb uninstall !APP_PKG!
|
| 258 |
+
adb uninstall !APP_PKG!
|
| 259 |
+
echo.
|
| 260 |
+
echo กด Enter กลับเมนู
|
| 261 |
+
pause >nul
|
| 262 |
+
goto MENU
|
| 263 |
+
|
| 264 |
+
:END
|
| 265 |
+
echo ออกจากโปรแกรม
|
| 266 |
+
exit /b 0
|
index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { registerRootComponent } from 'expo';
|
| 2 |
+
import App from './App';
|
| 3 |
+
registerRootComponent(App);
|
package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "chahuadev-code-editor",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"main": "index.js",
|
| 5 |
+
"scripts": {
|
| 6 |
+
"start": "expo start",
|
| 7 |
+
"android": "expo run:android",
|
| 8 |
+
"ios": "expo run:ios",
|
| 9 |
+
"web": "expo start --web"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"@react-navigation/native": "^7.1.19",
|
| 13 |
+
"@react-navigation/native-stack": "^7.4.2",
|
| 14 |
+
"babel-preset-expo": "~55.0.8",
|
| 15 |
+
"expo": "~55.0.8",
|
| 16 |
+
"expo-document-picker": "~55.0.5",
|
| 17 |
+
"expo-file-system": "~55.0.11",
|
| 18 |
+
"expo-sharing": "~55.0.14",
|
| 19 |
+
"expo-status-bar": "~55.0.4",
|
| 20 |
+
"react": "19.2.0",
|
| 21 |
+
"react-dom": "19.2.0",
|
| 22 |
+
"react-native": "0.83.2",
|
| 23 |
+
"react-native-gesture-handler": "~2.30.0",
|
| 24 |
+
"react-native-reanimated": "4.2.1",
|
| 25 |
+
"react-native-safe-area-context": "~5.6.2",
|
| 26 |
+
"react-native-screens": "~4.23.0",
|
| 27 |
+
"react-native-web": "^0.21.0",
|
| 28 |
+
"react-native-webview": "^13.12.5",
|
| 29 |
+
"react-native-worklets": "0.7.2"
|
| 30 |
+
},
|
| 31 |
+
"devDependencies": {
|
| 32 |
+
"@babel/core": "^7.20.0"
|
| 33 |
+
},
|
| 34 |
+
"private": true
|
| 35 |
+
}
|
src/screens/EditorScreen.js
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
| 2 |
+
import {
|
| 3 |
+
View, Text, StyleSheet, TouchableOpacity, TextInput, Alert,
|
| 4 |
+
ActivityIndicator, KeyboardAvoidingView, Platform,
|
| 5 |
+
ScrollView, useWindowDimensions, BackHandler, Keyboard,
|
| 6 |
+
} from 'react-native';
|
| 7 |
+
import { WebView } from 'react-native-webview';
|
| 8 |
+
import * as FileSystem from 'expo-file-system/legacy';
|
| 9 |
+
import * as Sharing from 'expo-sharing';
|
| 10 |
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
| 11 |
+
import { theme, getLanguage } from '../theme';
|
| 12 |
+
|
| 13 |
+
const MONACO_HTML = require('../../assets/monaco.html');
|
| 14 |
+
|
| 15 |
+
// ── Snippet bar data ─────────────────────────────────────────────────────────
|
| 16 |
+
// Covers: JS/TS, Python, HTML, CSS, Java, Kotlin, C/C++, Rust, Go, Swift, PHP, Ruby, SQL, Shell …
|
| 17 |
+
const SNIPPETS = [
|
| 18 |
+
// cursor navigation
|
| 19 |
+
{ t: '←', tip: 'cursor ←' },
|
| 20 |
+
{ t: '→', tip: 'cursor →' },
|
| 21 |
+
{ t: '⇥', tip: 'Indent' },
|
| 22 |
+
{ t: '⇤', tip: 'Dedent' },
|
| 23 |
+
{ sep: true },
|
| 24 |
+
// brackets
|
| 25 |
+
{ t: '(' }, { t: ')' },
|
| 26 |
+
{ t: '{' }, { t: '}' },
|
| 27 |
+
{ t: '[' }, { t: ']' },
|
| 28 |
+
{ t: '<' }, { t: '>' },
|
| 29 |
+
{ sep: true },
|
| 30 |
+
// punctuation
|
| 31 |
+
{ t: ';' }, { t: ':' }, { t: ',' }, { t: '.' },
|
| 32 |
+
{ t: '!' }, { t: '?' }, { t: '@' }, { t: '#' },
|
| 33 |
+
{ sep: true },
|
| 34 |
+
// assignment / compare
|
| 35 |
+
{ t: '=' }, { t: '=>' }, { t: '==' }, { t: '===' },
|
| 36 |
+
{ t: '!=' }, { t: '!==' }, { t: '>=' }, { t: '<=' },
|
| 37 |
+
{ sep: true },
|
| 38 |
+
// string / template
|
| 39 |
+
{ t: '"' }, { t: "'" }, { t: '`' }, { t: '\\' },
|
| 40 |
+
{ sep: true },
|
| 41 |
+
// arithmetic / bitwise
|
| 42 |
+
{ t: '+' }, { t: '-' }, { t: '*' }, { t: '/' },
|
| 43 |
+
{ t: '%' }, { t: '**' }, { t: '&' }, { t: '|' },
|
| 44 |
+
{ t: '^' }, { t: '~' }, { t: '<<' }, { t: '>>' },
|
| 45 |
+
{ sep: true },
|
| 46 |
+
// logical / nullish
|
| 47 |
+
{ t: '&&' }, { t: '||' }, { t: '??' }, { t: '?.' },
|
| 48 |
+
{ sep: true },
|
| 49 |
+
// compound assign
|
| 50 |
+
{ t: '+=' }, { t: '-=' }, { t: '*=' }, { t: '/=' },
|
| 51 |
+
{ t: '%=' }, { t: '**=' }, { t: '&&=' }, { t: '||=' },
|
| 52 |
+
{ sep: true },
|
| 53 |
+
// comment
|
| 54 |
+
{ t: '//' }, { t: '/*' }, { t: '*/' },
|
| 55 |
+
{ t: '<!--' }, { t: '-->' }, { t: '#!' },
|
| 56 |
+
{ sep: true },
|
| 57 |
+
// misc
|
| 58 |
+
{ t: '_' }, { t: '$' }, { t: '...' }, { t: '::' },
|
| 59 |
+
{ t: '->' }, { t: '<-' }, { t: '|>' }, { t: '::=' },
|
| 60 |
+
];
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
export default function EditorScreen({ route, navigation }) {
|
| 64 |
+
const { width, height } = useWindowDimensions();
|
| 65 |
+
const isLandscape = width > height;
|
| 66 |
+
const insets = useSafeAreaInsets();
|
| 67 |
+
const { fileUri, fileName } = route.params;
|
| 68 |
+
|
| 69 |
+
const webviewRef = useRef(null);
|
| 70 |
+
const nativeInputRef = useRef(null);
|
| 71 |
+
const saveGoBackRef = useRef(false);
|
| 72 |
+
const syncToNativeRef = useRef(false);
|
| 73 |
+
|
| 74 |
+
const [editorReady, setEditorReady] = useState(false);
|
| 75 |
+
const [isDirty, setIsDirty] = useState(false);
|
| 76 |
+
const [saving, setSaving] = useState(false);
|
| 77 |
+
const [fontSize, setFontSize] = useState(15);
|
| 78 |
+
const [wordWrap, setWordWrap] = useState(false);
|
| 79 |
+
const [snippetOpen, setSnippetOpen] = useState(true);
|
| 80 |
+
const [cursor, setCursor] = useState({ line: 1, col: 1, sel: 0 });
|
| 81 |
+
const [kbdVisible, setKbdVisible] = useState(false);
|
| 82 |
+
const [nativeMode, setNativeMode] = useState(Platform.OS === 'android');
|
| 83 |
+
const [nativeContent, setNativeContent] = useState('');
|
| 84 |
+
const [nativeSel, setNativeSel] = useState({ start: 0, end: 0 });
|
| 85 |
+
|
| 86 |
+
useEffect(() => {
|
| 87 |
+
const show = Keyboard.addListener('keyboardDidShow', () => setKbdVisible(true));
|
| 88 |
+
const hide = Keyboard.addListener('keyboardDidHide', () => setKbdVisible(false));
|
| 89 |
+
return () => { show.remove(); hide.remove(); };
|
| 90 |
+
}, []);
|
| 91 |
+
|
| 92 |
+
const loadFile = useCallback(async () => {
|
| 93 |
+
try {
|
| 94 |
+
const content = await FileSystem.readAsStringAsync(fileUri, { encoding: FileSystem.EncodingType.UTF8 });
|
| 95 |
+
setNativeContent(content);
|
| 96 |
+
sendCommand('setContent', { content, language: getLanguage(fileName) });
|
| 97 |
+
} catch (e) {
|
| 98 |
+
Alert.alert('Error reading file', e.message);
|
| 99 |
+
}
|
| 100 |
+
}, [fileUri, fileName]);
|
| 101 |
+
|
| 102 |
+
useEffect(() => { if (editorReady) loadFile(); }, [editorReady, loadFile]);
|
| 103 |
+
|
| 104 |
+
useEffect(() => {
|
| 105 |
+
const h = BackHandler.addEventListener('hardwareBackPress', () => { handleBack(); return true; });
|
| 106 |
+
return () => h.remove();
|
| 107 |
+
}, [isDirty]);
|
| 108 |
+
|
| 109 |
+
function sendCommand(type, extra = {}) {
|
| 110 |
+
if (!webviewRef.current) return;
|
| 111 |
+
const msg = JSON.stringify({ type, ...extra });
|
| 112 |
+
webviewRef.current.injectJavaScript(
|
| 113 |
+
`(function(){document.dispatchEvent(new MessageEvent('message',{data:${JSON.stringify(msg)}}));})();true;`
|
| 114 |
+
);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function handleBack() {
|
| 118 |
+
if (isDirty) {
|
| 119 |
+
Alert.alert('Unsaved changes', 'Save before leaving?', [
|
| 120 |
+
{ text: 'Discard', style: 'destructive', onPress: () => navigation.goBack() },
|
| 121 |
+
{ text: 'Save & Exit', onPress: () => doSave(true) },
|
| 122 |
+
{ text: 'Cancel', style: 'cancel' },
|
| 123 |
+
]);
|
| 124 |
+
} else { navigation.goBack(); }
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function doSave(thenGoBack = false) {
|
| 128 |
+
saveGoBackRef.current = thenGoBack;
|
| 129 |
+
setSaving(true);
|
| 130 |
+
if (nativeMode) writeContent(nativeContent);
|
| 131 |
+
else sendCommand('getContent');
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
async function writeContent(content) {
|
| 135 |
+
try {
|
| 136 |
+
await FileSystem.writeAsStringAsync(fileUri, content, { encoding: FileSystem.EncodingType.UTF8 });
|
| 137 |
+
setIsDirty(false);
|
| 138 |
+
sendCommand('markClean');
|
| 139 |
+
} catch (e) {
|
| 140 |
+
Alert.alert('Save failed', e.message);
|
| 141 |
+
} finally {
|
| 142 |
+
setSaving(false);
|
| 143 |
+
if (saveGoBackRef.current) { saveGoBackRef.current = false; navigation.goBack(); }
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
function onMessage(event) {
|
| 148 |
+
try {
|
| 149 |
+
const msg = JSON.parse(event.nativeEvent.data);
|
| 150 |
+
if (msg.type === 'ready') setEditorReady(true);
|
| 151 |
+
else if (msg.type === 'contentChanged') setIsDirty(true);
|
| 152 |
+
else if (msg.type === 'content') {
|
| 153 |
+
if (syncToNativeRef.current) {
|
| 154 |
+
syncToNativeRef.current = false;
|
| 155 |
+
setNativeContent(msg.content || '');
|
| 156 |
+
} else {
|
| 157 |
+
writeContent(msg.content);
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
else if (msg.type === 'fontSizeChanged') setFontSize(msg.size);
|
| 161 |
+
else if (msg.type === 'wordWrapChanged') setWordWrap(msg.enabled);
|
| 162 |
+
else if (msg.type === 'cursor') setCursor({ line: msg.line, col: msg.col, sel: msg.sel });
|
| 163 |
+
} catch {}
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
useEffect(() => {
|
| 167 |
+
if (!editorReady) return;
|
| 168 |
+
if (!nativeMode) {
|
| 169 |
+
sendCommand('setContent', { content: nativeContent, language: getLanguage(fileName) });
|
| 170 |
+
}
|
| 171 |
+
}, [nativeMode, editorReady]);
|
| 172 |
+
|
| 173 |
+
function updateNativeCursor(text, start, end) {
|
| 174 |
+
const upTo = text.slice(0, start);
|
| 175 |
+
const line = upTo.split('\n').length;
|
| 176 |
+
const col = start - upTo.lastIndexOf('\n');
|
| 177 |
+
setCursor({ line, col, sel: Math.max(0, end - start) });
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
function toggleEditorMode() {
|
| 181 |
+
if (nativeMode) {
|
| 182 |
+
setNativeMode(false);
|
| 183 |
+
return;
|
| 184 |
+
}
|
| 185 |
+
syncToNativeRef.current = true;
|
| 186 |
+
sendCommand('getContent');
|
| 187 |
+
setNativeMode(true);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
function nativeInsertText(t) {
|
| 191 |
+
const s = nativeSel.start;
|
| 192 |
+
const e = nativeSel.end;
|
| 193 |
+
const next = nativeContent.slice(0, s) + t + nativeContent.slice(e);
|
| 194 |
+
const p = s + t.length;
|
| 195 |
+
setNativeContent(next);
|
| 196 |
+
setNativeSel({ start: p, end: p });
|
| 197 |
+
setIsDirty(true);
|
| 198 |
+
updateNativeCursor(next, p, p);
|
| 199 |
+
requestAnimationFrame(() => nativeInputRef.current?.focus());
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
function runEditorAction(type, extra = {}) {
|
| 203 |
+
if (!nativeMode) {
|
| 204 |
+
sendCommand(type, extra);
|
| 205 |
+
return;
|
| 206 |
+
}
|
| 207 |
+
if (type === 'focusKeyboard') {
|
| 208 |
+
nativeInputRef.current?.focus();
|
| 209 |
+
return;
|
| 210 |
+
}
|
| 211 |
+
if (type === 'insertText') {
|
| 212 |
+
nativeInsertText(extra.text || '');
|
| 213 |
+
return;
|
| 214 |
+
}
|
| 215 |
+
if (type === 'fontSize') {
|
| 216 |
+
const next = Math.max(10, Math.min(32, fontSize + (extra.delta || 0)));
|
| 217 |
+
setFontSize(next);
|
| 218 |
+
return;
|
| 219 |
+
}
|
| 220 |
+
if (type === 'toggleWordWrap') return;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
const langLabel = getLanguage(fileName).toUpperCase();
|
| 224 |
+
const compact = isLandscape;
|
| 225 |
+
const snipH = compact ? 30 : 36;
|
| 226 |
+
const snipFs = compact ? 11 : 13;
|
| 227 |
+
|
| 228 |
+
return (
|
| 229 |
+
<KeyboardAvoidingView
|
| 230 |
+
style={[styles.container, { paddingTop: insets.top }]}
|
| 231 |
+
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
| 232 |
+
>
|
| 233 |
+
{/* ── Top bar ── */}
|
| 234 |
+
<View style={[styles.topBar, compact && styles.topBarCompact]}>
|
| 235 |
+
<TouchableOpacity style={styles.backBtn} onPress={handleBack}>
|
| 236 |
+
<Text style={[styles.backBtnText, compact && { fontSize: 22 }]}>‹</Text>
|
| 237 |
+
</TouchableOpacity>
|
| 238 |
+
<View style={styles.fileInfo}>
|
| 239 |
+
<Text style={[styles.fileName, compact && { fontSize: 12 }]} numberOfLines={1}>{fileName}</Text>
|
| 240 |
+
<Text style={styles.langBadge}>{langLabel}</Text>
|
| 241 |
+
{isDirty && <View style={styles.dirtyDot} />}
|
| 242 |
+
</View>
|
| 243 |
+
{/* Status inline */}
|
| 244 |
+
<Text style={styles.statusInline}>
|
| 245 |
+
{cursor.line}:{cursor.col}{cursor.sel > 0 ? ` [${cursor.sel}]` : ''}
|
| 246 |
+
</Text>
|
| 247 |
+
<TouchableOpacity
|
| 248 |
+
style={[styles.saveBtn, isDirty && styles.saveBtnActive]}
|
| 249 |
+
onPress={() => doSave(false)}
|
| 250 |
+
disabled={!isDirty || saving}
|
| 251 |
+
>
|
| 252 |
+
{saving
|
| 253 |
+
? <ActivityIndicator size="small" color={theme.colors.bg} />
|
| 254 |
+
: <Text style={[styles.saveBtnText, isDirty && styles.saveBtnTextActive]}>Save</Text>}
|
| 255 |
+
</TouchableOpacity>
|
| 256 |
+
</View>
|
| 257 |
+
|
| 258 |
+
{/* ── Main area: left sidebar + editor ── */}
|
| 259 |
+
<View style={styles.mainArea}>
|
| 260 |
+
|
| 261 |
+
{/* LEFT SIDEBAR ── vertical toolbar */}
|
| 262 |
+
<View style={styles.leftSidebar}>
|
| 263 |
+
<ScrollView
|
| 264 |
+
showsVerticalScrollIndicator={false}
|
| 265 |
+
keyboardShouldPersistTaps="always"
|
| 266 |
+
contentContainerStyle={styles.sidebarContent}
|
| 267 |
+
>
|
| 268 |
+
<SBtn label="↩" onPress={() => sendCommand('undo')} />
|
| 269 |
+
<SBtn label="↪" onPress={() => sendCommand('redo')} />
|
| 270 |
+
<SSep />
|
| 271 |
+
<SBtn label={nativeMode ? 'RN' : 'WEB'} active={!nativeMode} onPress={toggleEditorMode} />
|
| 272 |
+
<SSep />
|
| 273 |
+
<SBtn label="⌕" onPress={() => runEditorAction('find')} />
|
| 274 |
+
<SBtn label="fmt" onPress={() => runEditorAction('format')} />
|
| 275 |
+
<SBtn label="⌨" active={kbdVisible}
|
| 276 |
+
onPress={() => kbdVisible ? Keyboard.dismiss() : runEditorAction('focusKeyboard')} />
|
| 277 |
+
<SSep />
|
| 278 |
+
<SBtn label="dup" onPress={() => runEditorAction('duplicateLine')} />
|
| 279 |
+
<SBtn label="//" onPress={() => runEditorAction('toggleComment')} />
|
| 280 |
+
<SBtn label="↑" onPress={() => runEditorAction('lineUp')} />
|
| 281 |
+
<SBtn label="↓" onPress={() => runEditorAction('lineDown')} />
|
| 282 |
+
<SSep />
|
| 283 |
+
<SBtn label="A-" onPress={() => runEditorAction('fontSize', { delta: -1 })} />
|
| 284 |
+
<SBtn label={`${fontSize}`} disabled />
|
| 285 |
+
<SBtn label="A+" onPress={() => runEditorAction('fontSize', { delta: 1 })} />
|
| 286 |
+
<SSep />
|
| 287 |
+
<SBtn label="⇌" active={wordWrap} onPress={() => runEditorAction('toggleWordWrap')} />
|
| 288 |
+
<SSep />
|
| 289 |
+
<SBtn label="↑↑" onPress={() => Sharing.shareAsync(fileUri)} />
|
| 290 |
+
</ScrollView>
|
| 291 |
+
</View>
|
| 292 |
+
|
| 293 |
+
{/* EDITOR */}
|
| 294 |
+
<View style={styles.editorWrap}>
|
| 295 |
+
{!editorReady && (
|
| 296 |
+
<View style={styles.editorLoading}>
|
| 297 |
+
<ActivityIndicator size="large" color={theme.colors.accent} />
|
| 298 |
+
<Text style={styles.editorLoadingText}>Loading Monaco…</Text>
|
| 299 |
+
</View>
|
| 300 |
+
)}
|
| 301 |
+
{nativeMode ? (
|
| 302 |
+
<TextInput
|
| 303 |
+
ref={nativeInputRef}
|
| 304 |
+
style={[styles.nativeInput, { fontSize }]}
|
| 305 |
+
multiline
|
| 306 |
+
value={nativeContent}
|
| 307 |
+
onChangeText={(t) => {
|
| 308 |
+
setNativeContent(t);
|
| 309 |
+
setIsDirty(true);
|
| 310 |
+
}}
|
| 311 |
+
onSelectionChange={(e) => {
|
| 312 |
+
const s = e.nativeEvent.selection.start;
|
| 313 |
+
const en = e.nativeEvent.selection.end;
|
| 314 |
+
setNativeSel({ start: s, end: en });
|
| 315 |
+
updateNativeCursor(nativeContent, s, en);
|
| 316 |
+
}}
|
| 317 |
+
autoCorrect={false}
|
| 318 |
+
autoCapitalize="none"
|
| 319 |
+
spellCheck={false}
|
| 320 |
+
keyboardAppearance="dark"
|
| 321 |
+
textAlignVertical="top"
|
| 322 |
+
selectionColor={theme.colors.accent}
|
| 323 |
+
placeholder="Native editor mode (stable keyboard)"
|
| 324 |
+
placeholderTextColor={theme.colors.textMuted}
|
| 325 |
+
/>
|
| 326 |
+
) : (
|
| 327 |
+
<WebView
|
| 328 |
+
ref={webviewRef}
|
| 329 |
+
source={MONACO_HTML}
|
| 330 |
+
style={styles.webview}
|
| 331 |
+
onMessage={onMessage}
|
| 332 |
+
javaScriptEnabled
|
| 333 |
+
domStorageEnabled
|
| 334 |
+
originWhitelist={['*']}
|
| 335 |
+
mixedContentMode="always"
|
| 336 |
+
allowFileAccess
|
| 337 |
+
allowUniversalAccessFromFileURLs
|
| 338 |
+
scalesPageToFit={false}
|
| 339 |
+
textZoom={100}
|
| 340 |
+
overScrollMode="never"
|
| 341 |
+
nestedScrollEnabled={true}
|
| 342 |
+
keyboardDisplayRequiresUserAction={false}
|
| 343 |
+
hideKeyboardAccessoryView={true}
|
| 344 |
+
showsVerticalScrollIndicator={false}
|
| 345 |
+
showsHorizontalScrollIndicator={false}
|
| 346 |
+
onError={(e) => Alert.alert('WebView Error', e.nativeEvent.description)}
|
| 347 |
+
/>
|
| 348 |
+
)}
|
| 349 |
+
</View>
|
| 350 |
+
</View>
|
| 351 |
+
|
| 352 |
+
{/* ── Symbols bar — sits flush above keyboard ── */}
|
| 353 |
+
<View style={[styles.snippetBar, { paddingBottom: insets.bottom }]}>
|
| 354 |
+
<TouchableOpacity style={styles.snippetToggleRow} onPress={() => setSnippetOpen(o => !o)}>
|
| 355 |
+
<Text style={styles.snippetToggleLabel}>
|
| 356 |
+
{snippetOpen ? '▾ Symbols' : '▸ Symbols'}
|
| 357 |
+
</Text>
|
| 358 |
+
<Text style={styles.snippetToggleHint}>
|
| 359 |
+
{snippetOpen ? 'hide' : 'show'}
|
| 360 |
+
</Text>
|
| 361 |
+
</TouchableOpacity>
|
| 362 |
+
|
| 363 |
+
{snippetOpen && (
|
| 364 |
+
<ScrollView
|
| 365 |
+
horizontal
|
| 366 |
+
showsHorizontalScrollIndicator={false}
|
| 367 |
+
keyboardShouldPersistTaps="always"
|
| 368 |
+
contentContainerStyle={styles.snippetScroll}
|
| 369 |
+
>
|
| 370 |
+
{SNIPPETS.map((s, i) =>
|
| 371 |
+
s.sep
|
| 372 |
+
? <View key={`sp${i}`} style={styles.snippetSep} />
|
| 373 |
+
: (
|
| 374 |
+
<TouchableOpacity
|
| 375 |
+
key={`${s.t}${i}`}
|
| 376 |
+
style={[styles.snippetBtn, { height: snipH }]}
|
| 377 |
+
onPress={() => runEditorAction('insertText', { text: s.t })}
|
| 378 |
+
>
|
| 379 |
+
<Text style={[styles.snippetBtnText, { fontSize: snipFs }]}>{s.t}</Text>
|
| 380 |
+
</TouchableOpacity>
|
| 381 |
+
)
|
| 382 |
+
)}
|
| 383 |
+
</ScrollView>
|
| 384 |
+
)}
|
| 385 |
+
</View>
|
| 386 |
+
</KeyboardAvoidingView>
|
| 387 |
+
);
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
// ── Sub-components ────────────────────────────────────────────────────────────
|
| 391 |
+
function SBtn({ label, onPress, active, disabled }) {
|
| 392 |
+
return (
|
| 393 |
+
<TouchableOpacity
|
| 394 |
+
style={[styles.sideBtn, active && styles.sideBtnActive]}
|
| 395 |
+
onPress={onPress}
|
| 396 |
+
disabled={disabled}
|
| 397 |
+
activeOpacity={0.65}
|
| 398 |
+
>
|
| 399 |
+
<Text style={[styles.sideBtnText, active && styles.sideBtnTextActive, disabled && styles.sideBtnDim]}>
|
| 400 |
+
{label}
|
| 401 |
+
</Text>
|
| 402 |
+
</TouchableOpacity>
|
| 403 |
+
);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
function SSep() { return <View style={styles.sidebarSep} />; }
|
| 407 |
+
|
| 408 |
+
const styles = StyleSheet.create({
|
| 409 |
+
container: { flex: 1, backgroundColor: theme.colors.bg },
|
| 410 |
+
|
| 411 |
+
// top bar
|
| 412 |
+
topBar: {
|
| 413 |
+
flexDirection: 'row', alignItems: 'center', gap: 8,
|
| 414 |
+
paddingHorizontal: 10, paddingVertical: 8,
|
| 415 |
+
backgroundColor: theme.colors.surface,
|
| 416 |
+
borderBottomWidth: 1, borderBottomColor: theme.colors.border,
|
| 417 |
+
},
|
| 418 |
+
topBarCompact: { paddingVertical: 5 },
|
| 419 |
+
backBtn: { padding: 4 },
|
| 420 |
+
backBtnText: { color: theme.colors.accent, fontSize: 26, lineHeight: 28, fontWeight: '300' },
|
| 421 |
+
fileInfo: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: 6, overflow: 'hidden' },
|
| 422 |
+
fileName: { color: theme.colors.text, fontSize: 13, fontWeight: '700', flexShrink: 1 },
|
| 423 |
+
langBadge: {
|
| 424 |
+
color: theme.colors.textMuted, fontSize: 10, fontWeight: '700',
|
| 425 |
+
backgroundColor: theme.colors.surface2,
|
| 426 |
+
paddingHorizontal: 5, paddingVertical: 2, borderRadius: 4,
|
| 427 |
+
},
|
| 428 |
+
dirtyDot: { width: 7, height: 7, borderRadius: 4, backgroundColor: theme.colors.accentOrange },
|
| 429 |
+
statusInline: {
|
| 430 |
+
color: '#6b7280', fontSize: 10,
|
| 431 |
+
fontFamily: Platform.OS === 'android' ? 'monospace' : 'Courier New',
|
| 432 |
+
},
|
| 433 |
+
saveBtn: { paddingHorizontal: 12, paddingVertical: 6, borderRadius: 8, borderWidth: 1, borderColor: theme.colors.border },
|
| 434 |
+
saveBtnActive: { backgroundColor: theme.colors.accent, borderColor: theme.colors.accent },
|
| 435 |
+
saveBtnText: { color: theme.colors.textMuted, fontSize: 13, fontWeight: '700' },
|
| 436 |
+
saveBtnTextActive: { color: theme.colors.bg },
|
| 437 |
+
|
| 438 |
+
// main layout
|
| 439 |
+
mainArea: { flex: 1, flexDirection: 'row' },
|
| 440 |
+
|
| 441 |
+
// left sidebar
|
| 442 |
+
leftSidebar: {
|
| 443 |
+
width: 44,
|
| 444 |
+
backgroundColor: theme.colors.surface,
|
| 445 |
+
borderRightWidth: 1, borderRightColor: theme.colors.border,
|
| 446 |
+
},
|
| 447 |
+
sidebarContent: {
|
| 448 |
+
alignItems: 'center', paddingVertical: 6, gap: 3,
|
| 449 |
+
},
|
| 450 |
+
sideBtn: {
|
| 451 |
+
width: 36, height: 36, borderRadius: 8,
|
| 452 |
+
backgroundColor: theme.colors.surface2,
|
| 453 |
+
alignItems: 'center', justifyContent: 'center',
|
| 454 |
+
},
|
| 455 |
+
sideBtnActive: { backgroundColor: theme.colors.accent },
|
| 456 |
+
sideBtnText: { color: theme.colors.text, fontSize: 11, fontWeight: '700' },
|
| 457 |
+
sideBtnTextActive: { color: theme.colors.bg },
|
| 458 |
+
sideBtnDim: { color: theme.colors.textMuted },
|
| 459 |
+
sidebarSep: {
|
| 460 |
+
width: 24, height: 1,
|
| 461 |
+
backgroundColor: theme.colors.border,
|
| 462 |
+
marginVertical: 3,
|
| 463 |
+
},
|
| 464 |
+
|
| 465 |
+
// editor
|
| 466 |
+
editorWrap: { flex: 1, position: 'relative' },
|
| 467 |
+
webview: { flex: 1, backgroundColor: theme.colors.bg },
|
| 468 |
+
nativeInput: {
|
| 469 |
+
flex: 1,
|
| 470 |
+
color: theme.colors.text,
|
| 471 |
+
backgroundColor: theme.colors.bg,
|
| 472 |
+
paddingHorizontal: 10,
|
| 473 |
+
paddingTop: 12,
|
| 474 |
+
fontFamily: Platform.OS === 'android' ? 'monospace' : 'Courier New',
|
| 475 |
+
},
|
| 476 |
+
editorLoading: {
|
| 477 |
+
...StyleSheet.absoluteFillObject, backgroundColor: theme.colors.bg,
|
| 478 |
+
alignItems: 'center', justifyContent: 'center', zIndex: 10, gap: 12,
|
| 479 |
+
},
|
| 480 |
+
editorLoadingText: { color: theme.colors.textMuted, fontSize: 14 },
|
| 481 |
+
|
| 482 |
+
// snippet bar — no extra padding, KAV pushes it up flush against keyboard
|
| 483 |
+
snippetBar: {
|
| 484 |
+
backgroundColor: theme.colors.surface,
|
| 485 |
+
borderTopWidth: 1, borderTopColor: theme.colors.border,
|
| 486 |
+
},
|
| 487 |
+
snippetToggleRow: {
|
| 488 |
+
flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between',
|
| 489 |
+
paddingHorizontal: 12, paddingVertical: 4,
|
| 490 |
+
borderBottomWidth: 1, borderBottomColor: theme.colors.border + '60',
|
| 491 |
+
},
|
| 492 |
+
snippetToggleLabel: { color: theme.colors.accent, fontSize: 12, fontWeight: '700' },
|
| 493 |
+
snippetToggleHint: { color: theme.colors.textMuted, fontSize: 11 },
|
| 494 |
+
snippetScroll: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 8, gap: 3, paddingVertical: 3 },
|
| 495 |
+
snippetBtn: {
|
| 496 |
+
minWidth: 34, paddingHorizontal: 7, borderRadius: 7,
|
| 497 |
+
backgroundColor: theme.colors.surface2,
|
| 498 |
+
alignItems: 'center', justifyContent: 'center',
|
| 499 |
+
},
|
| 500 |
+
snippetBtnText: { color: theme.colors.accentGreen, fontWeight: '700', fontFamily: Platform.OS === 'android' ? 'monospace' : 'Courier New' },
|
| 501 |
+
snippetSep: { width: 1, height: 20, backgroundColor: theme.colors.border + '80', marginHorizontal: 3 },
|
| 502 |
+
});
|
src/screens/FileExplorerScreen.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useEffect, useCallback } from 'react';
|
| 2 |
+
import {
|
| 3 |
+
View, Text, StyleSheet, FlatList, TouchableOpacity,
|
| 4 |
+
TextInput, Alert, Modal, ActivityIndicator, BackHandler,
|
| 5 |
+
Platform,
|
| 6 |
+
} from 'react-native';
|
| 7 |
+
import * as FileSystem from 'expo-file-system/legacy';
|
| 8 |
+
import * as DocumentPicker from 'expo-document-picker';
|
| 9 |
+
import * as Sharing from 'expo-sharing';
|
| 10 |
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
| 11 |
+
import { theme, isEditable, getLangColor } from '../theme';
|
| 12 |
+
|
| 13 |
+
const ROOT = FileSystem.documentDirectory || 'file:///data/user/0/com.chahuadev.codeeditor/files/';
|
| 14 |
+
|
| 15 |
+
function sortEntries(entries) {
|
| 16 |
+
return [...entries].sort((a, b) => {
|
| 17 |
+
if (a.isDirectory !== b.isDirectory) return a.isDirectory ? -1 : 1;
|
| 18 |
+
return a.name.localeCompare(b.name);
|
| 19 |
+
});
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function FileIcon({ name, isDirectory, size = 16 }) {
|
| 23 |
+
if (isDirectory) return <Text style={[styles.fileIcon, { color: theme.colors.accentYellow, fontSize: size }]}>📁</Text>;
|
| 24 |
+
const ext = name.split('.').pop().toLowerCase();
|
| 25 |
+
const color = getLangColor(name);
|
| 26 |
+
const icons = { js: '', ts: '', py: '🐍', html: '', css: '🎨', json: '{}', md: '📝', sh: '>', txt: '📄', pdf: '📕', csv: '📊', xls: '📊', xlsx: '📊' };
|
| 27 |
+
const icon = icons[ext] || '📄';
|
| 28 |
+
return <Text style={[styles.fileIcon, { color, fontSize: size }]}>{icon}</Text>;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export default function FileExplorerScreen({ navigation }) {
|
| 32 |
+
const insets = useSafeAreaInsets();
|
| 33 |
+
const [currentPath, setCurrentPath] = useState(ROOT || '');
|
| 34 |
+
const [pathStack, setPathStack] = useState([]);
|
| 35 |
+
const [entries, setEntries] = useState([]);
|
| 36 |
+
const [loading, setLoading] = useState(false);
|
| 37 |
+
const [renameModal, setRenameModal] = useState(null);
|
| 38 |
+
const [newNameInput, setNewNameInput] = useState('');
|
| 39 |
+
const [newFileModal, setNewFileModal] = useState(false);
|
| 40 |
+
const [newFileName, setNewFileName] = useState('');
|
| 41 |
+
const [newFolderModal, setNewFolderModal] = useState(false);
|
| 42 |
+
const [newFolderName, setNewFolderName] = useState('');
|
| 43 |
+
const [searchQuery, setSearchQuery] = useState('');
|
| 44 |
+
|
| 45 |
+
const loadDir = useCallback(async (path) => {
|
| 46 |
+
setLoading(true);
|
| 47 |
+
try {
|
| 48 |
+
const items = await FileSystem.readDirectoryAsync(path);
|
| 49 |
+
const detailed = await Promise.all(
|
| 50 |
+
items.map(async (name) => {
|
| 51 |
+
const uri = path + name;
|
| 52 |
+
try {
|
| 53 |
+
const info = await FileSystem.getInfoAsync(uri);
|
| 54 |
+
return { name, uri, isDirectory: info.isDirectory, size: info.size || 0 };
|
| 55 |
+
} catch {
|
| 56 |
+
return { name, uri, isDirectory: false, size: 0 };
|
| 57 |
+
}
|
| 58 |
+
})
|
| 59 |
+
);
|
| 60 |
+
setEntries(sortEntries(detailed));
|
| 61 |
+
} catch (e) {
|
| 62 |
+
Alert.alert('Error', 'Could not read directory: ' + e.message);
|
| 63 |
+
} finally {
|
| 64 |
+
setLoading(false);
|
| 65 |
+
}
|
| 66 |
+
}, []);
|
| 67 |
+
|
| 68 |
+
useEffect(() => { loadDir(currentPath); }, [currentPath, loadDir]);
|
| 69 |
+
|
| 70 |
+
// Hardware back button
|
| 71 |
+
useEffect(() => {
|
| 72 |
+
const handler = BackHandler.addEventListener('hardwareBackPress', () => {
|
| 73 |
+
if (pathStack.length > 0) {
|
| 74 |
+
const prev = pathStack[pathStack.length - 1];
|
| 75 |
+
setPathStack(s => s.slice(0, -1));
|
| 76 |
+
setCurrentPath(prev);
|
| 77 |
+
return true;
|
| 78 |
+
}
|
| 79 |
+
return false;
|
| 80 |
+
});
|
| 81 |
+
return () => handler.remove();
|
| 82 |
+
}, [pathStack]);
|
| 83 |
+
|
| 84 |
+
function openEntry(entry) {
|
| 85 |
+
if (entry.isDirectory) {
|
| 86 |
+
setPathStack(s => [...s, currentPath]);
|
| 87 |
+
setCurrentPath(entry.uri + '/');
|
| 88 |
+
} else if (isEditable(entry.name)) {
|
| 89 |
+
navigation.navigate('Editor', { fileUri: entry.uri, fileName: entry.name });
|
| 90 |
+
} else {
|
| 91 |
+
Alert.alert('Cannot edit', `"${entry.name}" is not a text file.\n\nUse Share to open with another app.`, [
|
| 92 |
+
{ text: 'Share', onPress: () => Sharing.shareAsync(entry.uri) },
|
| 93 |
+
{ text: 'OK' },
|
| 94 |
+
]);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
function goUp() {
|
| 99 |
+
if (pathStack.length > 0) {
|
| 100 |
+
const prev = pathStack[pathStack.length - 1];
|
| 101 |
+
setPathStack(s => s.slice(0, -1));
|
| 102 |
+
setCurrentPath(prev);
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
async function deleteEntry(entry) {
|
| 107 |
+
Alert.alert('Delete', `Delete "${entry.name}"?`, [
|
| 108 |
+
{ text: 'Cancel', style: 'cancel' },
|
| 109 |
+
{
|
| 110 |
+
text: 'Delete', style: 'destructive',
|
| 111 |
+
onPress: async () => {
|
| 112 |
+
try {
|
| 113 |
+
await FileSystem.deleteAsync(entry.uri, { idempotent: true });
|
| 114 |
+
loadDir(currentPath);
|
| 115 |
+
} catch (e) {
|
| 116 |
+
Alert.alert('Error', e.message);
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
]);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
async function doRename() {
|
| 124 |
+
if (!newNameInput.trim()) return;
|
| 125 |
+
const oldUri = renameModal.uri;
|
| 126 |
+
const newUri = currentPath + newNameInput.trim() + (renameModal.isDirectory ? '/' : '');
|
| 127 |
+
try {
|
| 128 |
+
await FileSystem.moveAsync({ from: oldUri, to: newUri });
|
| 129 |
+
setRenameModal(null);
|
| 130 |
+
loadDir(currentPath);
|
| 131 |
+
} catch (e) {
|
| 132 |
+
Alert.alert('Error', e.message);
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
async function doCreateFile() {
|
| 137 |
+
const name = newFileName.trim();
|
| 138 |
+
if (!name) return;
|
| 139 |
+
const uri = currentPath + name;
|
| 140 |
+
try {
|
| 141 |
+
await FileSystem.writeAsStringAsync(uri, '');
|
| 142 |
+
setNewFileModal(false);
|
| 143 |
+
setNewFileName('');
|
| 144 |
+
loadDir(currentPath);
|
| 145 |
+
} catch (e) {
|
| 146 |
+
Alert.alert('Error', e.message);
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
async function doCreateFolder() {
|
| 151 |
+
const name = newFolderName.trim();
|
| 152 |
+
if (!name) return;
|
| 153 |
+
const uri = currentPath + name;
|
| 154 |
+
try {
|
| 155 |
+
await FileSystem.makeDirectoryAsync(uri, { intermediates: true });
|
| 156 |
+
setNewFolderModal(false);
|
| 157 |
+
setNewFolderName('');
|
| 158 |
+
loadDir(currentPath);
|
| 159 |
+
} catch (e) {
|
| 160 |
+
Alert.alert('Error', e.message);
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
async function importFile() {
|
| 165 |
+
try {
|
| 166 |
+
const result = await DocumentPicker.getDocumentAsync({ copyToCacheDirectory: false });
|
| 167 |
+
if (!result.canceled && result.assets?.length > 0) {
|
| 168 |
+
const asset = result.assets[0];
|
| 169 |
+
const dest = currentPath + asset.name;
|
| 170 |
+
await FileSystem.copyAsync({ from: asset.uri, to: dest });
|
| 171 |
+
loadDir(currentPath);
|
| 172 |
+
}
|
| 173 |
+
} catch (e) {
|
| 174 |
+
Alert.alert('Error', e.message);
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
const breadcrumb = (() => {
|
| 179 |
+
if (!currentPath || !ROOT) return '/';
|
| 180 |
+
const relative = currentPath.replace(ROOT, '');
|
| 181 |
+
return relative ? '/ ' + relative.replace(/\/$/, '') : '/';
|
| 182 |
+
})();
|
| 183 |
+
|
| 184 |
+
const filtered = searchQuery
|
| 185 |
+
? entries.filter(e => e.name.toLowerCase().includes(searchQuery.toLowerCase()))
|
| 186 |
+
: entries;
|
| 187 |
+
|
| 188 |
+
function formatSize(bytes) {
|
| 189 |
+
if (!bytes) return '';
|
| 190 |
+
if (bytes < 1024) return bytes + ' B';
|
| 191 |
+
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
| 192 |
+
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
return (
|
| 196 |
+
<View style={[styles.container, { paddingTop: insets.top }]}>
|
| 197 |
+
{/* Header */}
|
| 198 |
+
<View style={styles.header}>
|
| 199 |
+
<View style={styles.headerTop}>
|
| 200 |
+
<Text style={styles.title}>Files</Text>
|
| 201 |
+
<View style={styles.headerActions}>
|
| 202 |
+
<TouchableOpacity style={styles.actionBtn} onPress={importFile}>
|
| 203 |
+
<Text style={styles.actionBtnText}>Import</Text>
|
| 204 |
+
</TouchableOpacity>
|
| 205 |
+
<TouchableOpacity style={styles.actionBtn} onPress={() => setNewFolderModal(true)}>
|
| 206 |
+
<Text style={styles.actionBtnText}>+ Folder</Text>
|
| 207 |
+
</TouchableOpacity>
|
| 208 |
+
<TouchableOpacity style={[styles.actionBtn, styles.actionBtnAccent]} onPress={() => setNewFileModal(true)}>
|
| 209 |
+
<Text style={[styles.actionBtnText, { color: theme.colors.bg }]}>+ File</Text>
|
| 210 |
+
</TouchableOpacity>
|
| 211 |
+
</View>
|
| 212 |
+
</View>
|
| 213 |
+
|
| 214 |
+
{/* Breadcrumb */}
|
| 215 |
+
<View style={styles.breadcrumbRow}>
|
| 216 |
+
{pathStack.length > 0 && (
|
| 217 |
+
<TouchableOpacity onPress={goUp} style={styles.backBtn}>
|
| 218 |
+
<Text style={styles.backBtnText}>‹</Text>
|
| 219 |
+
</TouchableOpacity>
|
| 220 |
+
)}
|
| 221 |
+
<Text style={styles.breadcrumb} numberOfLines={1}>{breadcrumb}</Text>
|
| 222 |
+
</View>
|
| 223 |
+
|
| 224 |
+
{/* Search */}
|
| 225 |
+
<TextInput
|
| 226 |
+
style={styles.searchInput}
|
| 227 |
+
placeholder="Search files…"
|
| 228 |
+
placeholderTextColor={theme.colors.textMuted}
|
| 229 |
+
value={searchQuery}
|
| 230 |
+
onChangeText={setSearchQuery}
|
| 231 |
+
/>
|
| 232 |
+
</View>
|
| 233 |
+
|
| 234 |
+
{/* File List */}
|
| 235 |
+
{loading ? (
|
| 236 |
+
<View style={styles.loadingWrap}>
|
| 237 |
+
<ActivityIndicator color={theme.colors.accent} size="large" />
|
| 238 |
+
</View>
|
| 239 |
+
) : filtered.length === 0 ? (
|
| 240 |
+
<View style={styles.emptyWrap}>
|
| 241 |
+
<Text style={styles.emptyText}>{searchQuery ? 'No matches' : 'Empty folder'}</Text>
|
| 242 |
+
<Text style={styles.emptyHint}>Tap "+ File" to create a new file</Text>
|
| 243 |
+
</View>
|
| 244 |
+
) : (
|
| 245 |
+
<FlatList
|
| 246 |
+
data={filtered}
|
| 247 |
+
keyExtractor={item => item.uri}
|
| 248 |
+
contentContainerStyle={{ paddingBottom: insets.bottom + 16 }}
|
| 249 |
+
renderItem={({ item }) => (
|
| 250 |
+
<TouchableOpacity
|
| 251 |
+
style={styles.entryRow}
|
| 252 |
+
onPress={() => openEntry(item)}
|
| 253 |
+
onLongPress={() => {
|
| 254 |
+
Alert.alert(item.name, null, [
|
| 255 |
+
{ text: 'Rename', onPress: () => { setNewNameInput(item.name); setRenameModal(item); } },
|
| 256 |
+
{ text: 'Share', onPress: () => Sharing.shareAsync(item.uri) },
|
| 257 |
+
{ text: 'Delete', style: 'destructive', onPress: () => deleteEntry(item) },
|
| 258 |
+
{ text: 'Cancel', style: 'cancel' },
|
| 259 |
+
]);
|
| 260 |
+
}}
|
| 261 |
+
>
|
| 262 |
+
<FileIcon name={item.name} isDirectory={item.isDirectory} size={18} />
|
| 263 |
+
<View style={styles.entryInfo}>
|
| 264 |
+
<Text style={styles.entryName} numberOfLines={1}>{item.name}</Text>
|
| 265 |
+
{!item.isDirectory && item.size > 0 && (
|
| 266 |
+
<Text style={styles.entryMeta}>{formatSize(item.size)}</Text>
|
| 267 |
+
)}
|
| 268 |
+
</View>
|
| 269 |
+
<Text style={styles.entryArrow}>{item.isDirectory ? '›' : isEditable(item.name) ? '✎' : '↗'}</Text>
|
| 270 |
+
</TouchableOpacity>
|
| 271 |
+
)}
|
| 272 |
+
/>
|
| 273 |
+
)}
|
| 274 |
+
|
| 275 |
+
{/* Rename Modal */}
|
| 276 |
+
<Modal visible={!!renameModal} transparent animationType="fade">
|
| 277 |
+
<View style={styles.modalOverlay}>
|
| 278 |
+
<View style={styles.modalBox}>
|
| 279 |
+
<Text style={styles.modalTitle}>Rename</Text>
|
| 280 |
+
<TextInput
|
| 281 |
+
style={styles.modalInput}
|
| 282 |
+
value={newNameInput}
|
| 283 |
+
onChangeText={setNewNameInput}
|
| 284 |
+
autoFocus
|
| 285 |
+
selectTextOnFocus
|
| 286 |
+
/>
|
| 287 |
+
<View style={styles.modalRow}>
|
| 288 |
+
<TouchableOpacity style={styles.modalBtn} onPress={() => setRenameModal(null)}>
|
| 289 |
+
<Text style={styles.modalBtnText}>Cancel</Text>
|
| 290 |
+
</TouchableOpacity>
|
| 291 |
+
<TouchableOpacity style={[styles.modalBtn, styles.modalBtnAccent]} onPress={doRename}>
|
| 292 |
+
<Text style={[styles.modalBtnText, { color: theme.colors.bg }]}>Rename</Text>
|
| 293 |
+
</TouchableOpacity>
|
| 294 |
+
</View>
|
| 295 |
+
</View>
|
| 296 |
+
</View>
|
| 297 |
+
</Modal>
|
| 298 |
+
|
| 299 |
+
{/* New File Modal */}
|
| 300 |
+
<Modal visible={newFileModal} transparent animationType="fade">
|
| 301 |
+
<View style={styles.modalOverlay}>
|
| 302 |
+
<View style={styles.modalBox}>
|
| 303 |
+
<Text style={styles.modalTitle}>New File</Text>
|
| 304 |
+
<TextInput
|
| 305 |
+
style={styles.modalInput}
|
| 306 |
+
value={newFileName}
|
| 307 |
+
onChangeText={setNewFileName}
|
| 308 |
+
placeholder="filename.js"
|
| 309 |
+
placeholderTextColor={theme.colors.textMuted}
|
| 310 |
+
autoFocus
|
| 311 |
+
/>
|
| 312 |
+
<View style={styles.modalRow}>
|
| 313 |
+
<TouchableOpacity style={styles.modalBtn} onPress={() => { setNewFileModal(false); setNewFileName(''); }}>
|
| 314 |
+
<Text style={styles.modalBtnText}>Cancel</Text>
|
| 315 |
+
</TouchableOpacity>
|
| 316 |
+
<TouchableOpacity style={[styles.modalBtn, styles.modalBtnAccent]} onPress={doCreateFile}>
|
| 317 |
+
<Text style={[styles.modalBtnText, { color: theme.colors.bg }]}>Create</Text>
|
| 318 |
+
</TouchableOpacity>
|
| 319 |
+
</View>
|
| 320 |
+
</View>
|
| 321 |
+
</View>
|
| 322 |
+
</Modal>
|
| 323 |
+
|
| 324 |
+
{/* New Folder Modal */}
|
| 325 |
+
<Modal visible={newFolderModal} transparent animationType="fade">
|
| 326 |
+
<View style={styles.modalOverlay}>
|
| 327 |
+
<View style={styles.modalBox}>
|
| 328 |
+
<Text style={styles.modalTitle}>New Folder</Text>
|
| 329 |
+
<TextInput
|
| 330 |
+
style={styles.modalInput}
|
| 331 |
+
value={newFolderName}
|
| 332 |
+
onChangeText={setNewFolderName}
|
| 333 |
+
placeholder="folder-name"
|
| 334 |
+
placeholderTextColor={theme.colors.textMuted}
|
| 335 |
+
autoFocus
|
| 336 |
+
/>
|
| 337 |
+
<View style={styles.modalRow}>
|
| 338 |
+
<TouchableOpacity style={styles.modalBtn} onPress={() => { setNewFolderModal(false); setNewFolderName(''); }}>
|
| 339 |
+
<Text style={styles.modalBtnText}>Cancel</Text>
|
| 340 |
+
</TouchableOpacity>
|
| 341 |
+
<TouchableOpacity style={[styles.modalBtn, styles.modalBtnAccent]} onPress={doCreateFolder}>
|
| 342 |
+
<Text style={[styles.modalBtnText, { color: theme.colors.bg }]}>Create</Text>
|
| 343 |
+
</TouchableOpacity>
|
| 344 |
+
</View>
|
| 345 |
+
</View>
|
| 346 |
+
</View>
|
| 347 |
+
</Modal>
|
| 348 |
+
</View>
|
| 349 |
+
);
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
const styles = StyleSheet.create({
|
| 353 |
+
container: { flex: 1, backgroundColor: theme.colors.bg },
|
| 354 |
+
header: { backgroundColor: theme.colors.surface, paddingHorizontal: 16, paddingBottom: 10, borderBottomWidth: 1, borderBottomColor: theme.colors.border },
|
| 355 |
+
headerTop: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingTop: 12, paddingBottom: 6 },
|
| 356 |
+
title: { color: theme.colors.text, fontSize: 20, fontWeight: '800' },
|
| 357 |
+
headerActions: { flexDirection: 'row', gap: 8 },
|
| 358 |
+
actionBtn: { paddingHorizontal: 10, paddingVertical: 6, borderRadius: 8, borderWidth: 1, borderColor: theme.colors.border },
|
| 359 |
+
actionBtnAccent: { backgroundColor: theme.colors.accent, borderColor: theme.colors.accent },
|
| 360 |
+
actionBtnText: { color: theme.colors.text, fontSize: 12, fontWeight: '700' },
|
| 361 |
+
breadcrumbRow: { flexDirection: 'row', alignItems: 'center', gap: 8, marginBottom: 8 },
|
| 362 |
+
backBtn: { padding: 4 },
|
| 363 |
+
backBtnText: { color: theme.colors.accent, fontSize: 22, lineHeight: 24 },
|
| 364 |
+
breadcrumb: { color: theme.colors.textMuted, fontSize: 12, flex: 1 },
|
| 365 |
+
searchInput: { backgroundColor: theme.colors.surface2, color: theme.colors.text, borderRadius: 8, paddingHorizontal: 12, paddingVertical: 8, fontSize: 14 },
|
| 366 |
+
loadingWrap: { flex: 1, alignItems: 'center', justifyContent: 'center' },
|
| 367 |
+
emptyWrap: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 8 },
|
| 368 |
+
emptyText: { color: theme.colors.textMuted, fontSize: 16 },
|
| 369 |
+
emptyHint: { color: theme.colors.textMuted, fontSize: 12 },
|
| 370 |
+
entryRow: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16, paddingVertical: 13, borderBottomWidth: 1, borderBottomColor: theme.colors.border + '55', gap: 12 },
|
| 371 |
+
fileIcon: { width: 24, textAlign: 'center' },
|
| 372 |
+
entryInfo: { flex: 1 },
|
| 373 |
+
entryName: { color: theme.colors.text, fontSize: 14, fontWeight: '600' },
|
| 374 |
+
entryMeta: { color: theme.colors.textMuted, fontSize: 11, marginTop: 1 },
|
| 375 |
+
entryArrow: { color: theme.colors.textMuted, fontSize: 16 },
|
| 376 |
+
modalOverlay: { flex: 1, backgroundColor: '#000000aa', alignItems: 'center', justifyContent: 'center' },
|
| 377 |
+
modalBox: { backgroundColor: theme.colors.surface, borderRadius: 14, padding: 20, width: 280, gap: 12, borderWidth: 1, borderColor: theme.colors.border },
|
| 378 |
+
modalTitle: { color: theme.colors.text, fontSize: 16, fontWeight: '800' },
|
| 379 |
+
modalInput: { backgroundColor: theme.colors.surface2, color: theme.colors.text, borderRadius: 8, paddingHorizontal: 12, paddingVertical: 10, fontSize: 14 },
|
| 380 |
+
modalRow: { flexDirection: 'row', justifyContent: 'flex-end', gap: 10 },
|
| 381 |
+
modalBtn: { paddingHorizontal: 14, paddingVertical: 8, borderRadius: 8, borderWidth: 1, borderColor: theme.colors.border },
|
| 382 |
+
modalBtnAccent: { backgroundColor: theme.colors.accent, borderColor: theme.colors.accent },
|
| 383 |
+
modalBtnText: { color: theme.colors.text, fontSize: 13, fontWeight: '700' },
|
| 384 |
+
});
|
src/screens/SplashScreen.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useEffect, useRef } from 'react'
|
| 2 |
+
import {
|
| 3 |
+
View, Text, StyleSheet, Animated, Easing, Dimensions,
|
| 4 |
+
} from 'react-native'
|
| 5 |
+
|
| 6 |
+
const { height: SCREEN_H } = Dimensions.get('window')
|
| 7 |
+
|
| 8 |
+
const ACCENT = '#60a5fa'
|
| 9 |
+
const ACCENT_DIM = 'rgba(59,130,246,0.12)'
|
| 10 |
+
const ACCENT_BORDER = 'rgba(59,130,246,0.38)'
|
| 11 |
+
|
| 12 |
+
export default function SplashScreen({ onDone }) {
|
| 13 |
+
const scanAnim = useRef(new Animated.Value(0)).current
|
| 14 |
+
const progAnim = useRef(new Animated.Value(0)).current
|
| 15 |
+
const fadeAnim = useRef(new Animated.Value(1)).current
|
| 16 |
+
|
| 17 |
+
useEffect(() => {
|
| 18 |
+
Animated.loop(
|
| 19 |
+
Animated.timing(scanAnim, {
|
| 20 |
+
toValue: 1,
|
| 21 |
+
duration: 3200,
|
| 22 |
+
easing: Easing.linear,
|
| 23 |
+
useNativeDriver: true,
|
| 24 |
+
})
|
| 25 |
+
).start()
|
| 26 |
+
|
| 27 |
+
Animated.timing(progAnim, {
|
| 28 |
+
toValue: 1,
|
| 29 |
+
duration: 2600,
|
| 30 |
+
easing: Easing.out(Easing.quad),
|
| 31 |
+
useNativeDriver: false,
|
| 32 |
+
}).start()
|
| 33 |
+
|
| 34 |
+
const t = setTimeout(() => {
|
| 35 |
+
Animated.timing(fadeAnim, {
|
| 36 |
+
toValue: 0,
|
| 37 |
+
duration: 280,
|
| 38 |
+
useNativeDriver: true,
|
| 39 |
+
}).start(() => onDone && onDone())
|
| 40 |
+
}, 2900)
|
| 41 |
+
|
| 42 |
+
return () => clearTimeout(t)
|
| 43 |
+
}, [])
|
| 44 |
+
|
| 45 |
+
const scanTranslate = scanAnim.interpolate({
|
| 46 |
+
inputRange: [0, 1],
|
| 47 |
+
outputRange: [-2, SCREEN_H + 2],
|
| 48 |
+
})
|
| 49 |
+
|
| 50 |
+
const progWidth = progAnim.interpolate({
|
| 51 |
+
inputRange: [0, 1],
|
| 52 |
+
outputRange: ['0%', '100%'],
|
| 53 |
+
})
|
| 54 |
+
|
| 55 |
+
return (
|
| 56 |
+
<Animated.View style={[styles.root, { opacity: fadeAnim }]}>
|
| 57 |
+
{/* Orb glow */}
|
| 58 |
+
<View style={styles.orbTop} />
|
| 59 |
+
<View style={styles.orbBottom} />
|
| 60 |
+
|
| 61 |
+
{/* Scan line */}
|
| 62 |
+
<Animated.View
|
| 63 |
+
style={[styles.scanLine, { transform: [{ translateY: scanTranslate }] }]}
|
| 64 |
+
/>
|
| 65 |
+
|
| 66 |
+
{/* Content */}
|
| 67 |
+
<View style={styles.content}>
|
| 68 |
+
{/* Badge pill */}
|
| 69 |
+
<View style={styles.pill}>
|
| 70 |
+
<Text style={styles.pillText}>✎ LOCAL FILES · SYNTAX HIGHLIGHT</Text>
|
| 71 |
+
</View>
|
| 72 |
+
|
| 73 |
+
{/* Title */}
|
| 74 |
+
<Text style={styles.title}>Code{'\n'}Editor</Text>
|
| 75 |
+
|
| 76 |
+
{/* Subtitle */}
|
| 77 |
+
<Text style={styles.subtitle}>
|
| 78 |
+
Edit your local files with full syntax highlighting.
|
| 79 |
+
</Text>
|
| 80 |
+
|
| 81 |
+
{/* Progress bar */}
|
| 82 |
+
<View style={styles.progWrap}>
|
| 83 |
+
<Animated.View style={[styles.progBar, { width: progWidth }]} />
|
| 84 |
+
</View>
|
| 85 |
+
</View>
|
| 86 |
+
|
| 87 |
+
{/* Version */}
|
| 88 |
+
<Text style={styles.version}>v1.0.0</Text>
|
| 89 |
+
</Animated.View>
|
| 90 |
+
)
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
const styles = StyleSheet.create({
|
| 94 |
+
root: {
|
| 95 |
+
flex: 1,
|
| 96 |
+
backgroundColor: '#08090f',
|
| 97 |
+
alignItems: 'center',
|
| 98 |
+
justifyContent: 'center',
|
| 99 |
+
},
|
| 100 |
+
orbTop: {
|
| 101 |
+
position: 'absolute',
|
| 102 |
+
top: -80,
|
| 103 |
+
left: -60,
|
| 104 |
+
width: 380,
|
| 105 |
+
height: 380,
|
| 106 |
+
borderRadius: 190,
|
| 107 |
+
backgroundColor: 'rgba(37,99,235,0.13)',
|
| 108 |
+
},
|
| 109 |
+
orbBottom: {
|
| 110 |
+
position: 'absolute',
|
| 111 |
+
bottom: -120,
|
| 112 |
+
right: -80,
|
| 113 |
+
width: 300,
|
| 114 |
+
height: 300,
|
| 115 |
+
borderRadius: 150,
|
| 116 |
+
backgroundColor: 'rgba(59,130,246,0.07)',
|
| 117 |
+
},
|
| 118 |
+
scanLine: {
|
| 119 |
+
position: 'absolute',
|
| 120 |
+
left: 0,
|
| 121 |
+
right: 0,
|
| 122 |
+
top: 0,
|
| 123 |
+
height: 2,
|
| 124 |
+
backgroundColor: ACCENT,
|
| 125 |
+
opacity: 0.55,
|
| 126 |
+
},
|
| 127 |
+
content: {
|
| 128 |
+
alignItems: 'center',
|
| 129 |
+
paddingHorizontal: 32,
|
| 130 |
+
zIndex: 10,
|
| 131 |
+
},
|
| 132 |
+
pill: {
|
| 133 |
+
flexDirection: 'row',
|
| 134 |
+
alignItems: 'center',
|
| 135 |
+
paddingVertical: 5,
|
| 136 |
+
paddingHorizontal: 14,
|
| 137 |
+
borderRadius: 20,
|
| 138 |
+
borderWidth: 1,
|
| 139 |
+
borderColor: ACCENT_BORDER,
|
| 140 |
+
backgroundColor: ACCENT_DIM,
|
| 141 |
+
marginBottom: 20,
|
| 142 |
+
},
|
| 143 |
+
pillText: {
|
| 144 |
+
color: '#93c5fd',
|
| 145 |
+
fontSize: 10,
|
| 146 |
+
fontWeight: '700',
|
| 147 |
+
letterSpacing: 1.1,
|
| 148 |
+
textTransform: 'uppercase',
|
| 149 |
+
},
|
| 150 |
+
title: {
|
| 151 |
+
fontSize: 72,
|
| 152 |
+
fontWeight: '900',
|
| 153 |
+
color: '#bfdbfe',
|
| 154 |
+
textAlign: 'center',
|
| 155 |
+
lineHeight: 72,
|
| 156 |
+
letterSpacing: -2,
|
| 157 |
+
marginBottom: 12,
|
| 158 |
+
},
|
| 159 |
+
subtitle: {
|
| 160 |
+
fontSize: 13,
|
| 161 |
+
color: '#4a5068',
|
| 162 |
+
textAlign: 'center',
|
| 163 |
+
letterSpacing: 0.3,
|
| 164 |
+
marginBottom: 32,
|
| 165 |
+
lineHeight: 19,
|
| 166 |
+
},
|
| 167 |
+
progWrap: {
|
| 168 |
+
width: 180,
|
| 169 |
+
height: 2,
|
| 170 |
+
backgroundColor: 'rgba(255,255,255,0.06)',
|
| 171 |
+
borderRadius: 1,
|
| 172 |
+
overflow: 'hidden',
|
| 173 |
+
},
|
| 174 |
+
progBar: {
|
| 175 |
+
height: '100%',
|
| 176 |
+
backgroundColor: ACCENT,
|
| 177 |
+
borderRadius: 1,
|
| 178 |
+
},
|
| 179 |
+
version: {
|
| 180 |
+
position: 'absolute',
|
| 181 |
+
bottom: 20,
|
| 182 |
+
right: 20,
|
| 183 |
+
fontSize: 10,
|
| 184 |
+
color: '#252830',
|
| 185 |
+
},
|
| 186 |
+
})
|
src/theme.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const theme = {
|
| 2 |
+
colors: {
|
| 3 |
+
bg: '#0e0e14',
|
| 4 |
+
surface: '#1a1a2e',
|
| 5 |
+
surface2: '#2d2d44',
|
| 6 |
+
border: '#2d2d44',
|
| 7 |
+
accent: '#818cf8',
|
| 8 |
+
accentGreen: '#6ee7b7',
|
| 9 |
+
accentOrange: '#fb923c',
|
| 10 |
+
accentBlue: '#38bdf8',
|
| 11 |
+
accentYellow: '#fbbf24',
|
| 12 |
+
text: '#e2e8f0',
|
| 13 |
+
textMuted: '#6b7280',
|
| 14 |
+
warn: '#fb923c',
|
| 15 |
+
danger: '#f87171',
|
| 16 |
+
success: '#6ee7b7',
|
| 17 |
+
},
|
| 18 |
+
radius: 10,
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
// Map file extensions to Monaco language IDs
|
| 22 |
+
export function getLanguage(filename) {
|
| 23 |
+
if (!filename) return 'plaintext';
|
| 24 |
+
const ext = filename.split('.').pop().toLowerCase();
|
| 25 |
+
const map = {
|
| 26 |
+
js: 'javascript', jsx: 'javascript',
|
| 27 |
+
ts: 'typescript', tsx: 'typescript',
|
| 28 |
+
py: 'python',
|
| 29 |
+
html: 'html', htm: 'html',
|
| 30 |
+
css: 'css', scss: 'scss', less: 'less',
|
| 31 |
+
json: 'json',
|
| 32 |
+
md: 'markdown', mdx: 'markdown',
|
| 33 |
+
xml: 'xml',
|
| 34 |
+
yaml: 'yaml', yml: 'yaml',
|
| 35 |
+
sh: 'shell', bash: 'shell',
|
| 36 |
+
java: 'java',
|
| 37 |
+
kt: 'kotlin',
|
| 38 |
+
swift: 'swift',
|
| 39 |
+
cpp: 'cpp', cc: 'cpp', cxx: 'cpp',
|
| 40 |
+
c: 'c', h: 'c',
|
| 41 |
+
cs: 'csharp',
|
| 42 |
+
go: 'go',
|
| 43 |
+
rs: 'rust',
|
| 44 |
+
rb: 'ruby',
|
| 45 |
+
php: 'php',
|
| 46 |
+
sql: 'sql',
|
| 47 |
+
r: 'r',
|
| 48 |
+
dart: 'dart',
|
| 49 |
+
lua: 'lua',
|
| 50 |
+
toml: 'ini',
|
| 51 |
+
ini: 'ini', cfg: 'ini', conf: 'ini',
|
| 52 |
+
txt: 'plaintext',
|
| 53 |
+
log: 'plaintext',
|
| 54 |
+
csv: 'plaintext',
|
| 55 |
+
};
|
| 56 |
+
return map[ext] || 'plaintext';
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// Icon color per language family
|
| 60 |
+
export function getLangColor(filename) {
|
| 61 |
+
const lang = getLanguage(filename);
|
| 62 |
+
if (['javascript', 'typescript'].includes(lang)) return '#fbbf24';
|
| 63 |
+
if (lang === 'python') return '#38bdf8';
|
| 64 |
+
if (['html', 'xml'].includes(lang)) return '#fb923c';
|
| 65 |
+
if (['css', 'scss', 'less'].includes(lang)) return '#818cf8';
|
| 66 |
+
if (lang === 'json') return '#6ee7b7';
|
| 67 |
+
if (lang === 'markdown') return '#94a3b8';
|
| 68 |
+
if (lang === 'shell') return '#6ee7b7';
|
| 69 |
+
if (['java', 'kotlin'].includes(lang)) return '#f87171';
|
| 70 |
+
if (lang === 'rust') return '#fb923c';
|
| 71 |
+
if (lang === 'go') return '#38bdf8';
|
| 72 |
+
return '#6b7280';
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// Binary / non-editable file types
|
| 76 |
+
const BINARY_EXTS = ['pdf', 'xls', 'xlsx', 'doc', 'docx', 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'svg', 'zip', 'tar', 'gz', 'apk', 'aar', 'jar', 'so', 'dylib', 'exe', 'mp4', 'mp3', 'wav'];
|
| 77 |
+
|
| 78 |
+
export function isEditable(filename) {
|
| 79 |
+
if (!filename) return false;
|
| 80 |
+
const ext = filename.split('.').pop().toLowerCase();
|
| 81 |
+
return !BINARY_EXTS.includes(ext);
|
| 82 |
+
}
|