A comprehensive React + Vite application to test and demonstrate the Monaco Editor component with all its features.
This test app showcases the following Monaco Editor features:
- Multiple Language Support: JavaScript, TypeScript, Python, Java, JSON, N1QL, SQL++, Shell, and plain text
- Custom Languages: N1QL and SQL++ with custom syntax highlighting
- Theme Switching: Toggle between light and dark themes
- Configurable Options:
- Font size adjustment (10-30px)
- Read-only mode
- Word wrap toggle
- Optional run button
- Syntax Highlighting: Full syntax highlighting for all supported languages
- Monaco Editor Core: Powered by the same editor that powers VS Code
- Navigate to the project directory:
cd editor-test-app- Install dependencies:
npm installStart the development server:
npm run devThe app will be available at http://localhost:5173 (or another port if 5173 is busy)
npm run buildnpm run preview- Select a Language: Click on any language button to switch the editor language
- Change Theme: Toggle between dark and light themes
- Adjust Font Size: Use the slider to change the editor font size
- Toggle Options:
- Enable/disable read-only mode
- Show/hide the run button
- Toggle word wrap
- Run Code: Click the play button (if enabled) to execute the current code
- Edit Code: Type directly in the editor to modify the code
editor-test-app/
├── src/
│ ├── components/
│ │ ├── editor/
│ │ │ ├── editor.tsx # Main editor component
│ │ │ ├── editor.types.ts # TypeScript types
│ │ │ ├── languages/
│ │ │ │ ├── custom/
│ │ │ │ │ ├── n1ql/ # N1QL language support
│ │ │ │ │ ├── sql-plus-plus/ # SQL++ language support
│ │ │ │ │ └── custom-java/ # Custom Java support
│ │ │ │ └── types.ts
│ │ │ ├── utils/
│ │ │ │ ├── configure-monaco.ts # Monaco configuration
│ │ │ │ ├── custom-languages.ts # Custom language utilities
│ │ │ │ └── get-styles.ts # Style utilities
│ │ │ └── styles/
│ │ │ └── editor.scss
│ │ ├── icon/
│ │ │ ├── icon.tsx # Icon component
│ │ │ └── icon.types.ts
│ │ └── spinner/
│ │ ├── spinner.tsx # Spinner component
│ │ ├── spinner.types.ts
│ │ └── spinner.module.scss
│ ├── styles/
│ │ └── variables.scss
│ ├── App.tsx # Main app component
│ ├── App.css # App styles
│ ├── main.tsx # Entry point
│ └── index.css # Global styles
├── index.html
├── package.json
├── tsconfig.json
├── vite.config.ts
└── README.md
- React 18: UI framework
- Vite: Build tool and dev server
- TypeScript: Type safety
- Monaco Editor: Code editor component
- @monaco-editor/react: React wrapper for Monaco
- Sass: CSS preprocessing
The editor can be configured through the following props:
editorId: Unique identifier for the editorlanguage: Programming language (see SupportedLanguage type)value: Initial code valuetheme: 'vs-dark' or 'vs-light'onRun: Callback function for the run buttonreadOnly: Make the editor read-onlyfontSize: Font size in pixelslineHeight: Line height multiplierwordWrap: Word wrap setting ('on' | 'off' | 'wordWrapColumn' | 'bounded')onChange: Callback for content changesonDidPaste: Callback for paste eventsheight: Editor height (CSS dimension)
import { Editor } from './components/editor/editor';
function MyComponent() {
const handleRun = () => {
console.log('Code executed!');
};
return (
<Editor
language="javascript"
value="console.log('Hello, World!');"
theme="vs-dark"
onRun={handleRun}
fontSize={16}
height="400px"
/>
);
}The app includes custom language support for:
Couchbase N1QL (SQL for JSON) with keywords like SELECT, FROM, WHERE, UNNEST, etc.
Enhanced SQL with additional features for JSON data manipulation.
Java with custom configurations.
If you encounter any issues:
- Port already in use: Vite will automatically try the next available port
- Dependencies not installed: Run
npm installagain - Build errors: Try deleting
node_modulesand runningnpm installagain - Editor not loading: Check browser console for errors
This is a test application for demonstration purposes.
This is a test app. Feel free to modify and extend it as needed.
For issues with the Monaco Editor component itself, refer to the original implementation in the VSCode-Couchbase project.