x-editor-react
v0.0.9
Published
A monaco-based code editor with live preview.
Downloads
1
Readme
x-editor-react
A monaco-based code editor with live preview.
Install
pnpm add monaco-editor x-editor-react
Setup worker
- vite
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
window.MonacoEnvironment = {
getWorker(_, label) {
if (label === 'json') {
return new jsonWorker();
}
if (label === 'css' || label === 'scss' || label === 'less') {
return new cssWorker();
}
if (label === 'html' || label === 'handlebars' || label === 'razor') {
return new htmlWorker();
}
if (label === 'typescript' || label === 'javascript') {
return new tsWorker();
}
return new editorWorker();
}
};
- webpack
Usage
Basic usage
import XEditor from 'x-editor-react';
const code = `const a = 1;`;
export default function App() {
return <XEditor code={code} />;
}