Provides the view layer of a modular browser text and code editor.
Downloads / mo 90.6M
Stars 178
Last release 6.43.15
License MIT Strengths Selects features through separate modules . Choose the editor features the application needs. Adds configurable gutter controls . Use line numbers or build custom controls beside the code. Limitations Editing features need assembly . Install and import the separate editing features the application needs. $ npm install @codemirror/view@6.43.15 codemirror@6.0.2 Copy
import { basicSetup } from 'codemirror';
import { EditorView } from '@codemirror/view';
new EditorView({ doc: 'Hello world', parent: document.body, extensions: [basicSetup] });
CodeMirror examples From open-source projects on GitHub revealSelection(
selection: CodeEditor.IRange,
options?: ScrollIntoViewOptions
): void {
const start = this.getOffsetAt(selection.start);
const end = this.getOffsetAt(selection.end);
this._editor.dispatch({
effects: EditorView.scrollIntoView(EditorSelection.range(start, end), {
y: options?.block,
x: options?.inline
})
});
}
Show full example Provides the browser editor generated from Visual Studio Code sources.
Downloads / mo 51.9M
Stars 47.0K
Last release 0.57.0
License MIT Strengths Supports language completion providers . Add completion items for the current document and cursor position. Allows custom syntax highlighting . Define syntax highlighting through a declarative Monarch specification. Limitations Workers need a web server . Serve the editor over HTTP or HTTPS so workers can start. Mobile browsers are unsupported . Choose another editor when mobile browser support is required. $ npm install monaco-editor@0.57.0 Copy
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
self.MonacoEnvironment = { getWorker: () => new EditorWorker() };
const host = document.body.appendChild(document.createElement('div'));
host.style.height = '200px';
monaco.editor.create(host, { value: 'Hello world', language: 'plaintext' });
Monaco Editor examples From open-source projects on GitHub function disposeEditor() {
subscriptionRef.current?.dispose();
if (keepCurrentModel) {
saveViewState && viewStates.set(path, editorRef.current!.saveViewState());
} else {
editorRef.current!.getModel()?.dispose();
}
editorRef.current!.dispose();
editorRef.current = null;
preventCreation.current = false;
setIsEditorReady(false);
}
Show full example Provides prepackaged browser builds of the Ace code editor.
Downloads / mo 7.9M
Stars 3.1K
Last release 1.45.2
License BSD-3-Clause Strengths Groups edits for undo . Control which edits belong to the same undo step. Supports editor markers . Add editor ranges with custom styles through the session marker API. Limitations Completion needs its extension file . Load ext-language_tools.js before enabling autocomplete. $ npm install ace-builds@1.45.2 Copy
import * as ace from 'ace-builds';
const host = document.body.appendChild(document.createElement('div'));
host.style.height = '200px';
ace.edit(host, { value: 'Hello world', mode: 'ace/mode/text' });
Ace examples From open-source projects on GitHub public handleMarkers(markers: IMarker[]) {
// remove foreground markers
let currentMarkers = this.editor.getSession().getMarkers(true);
for (const i in currentMarkers) {
if (currentMarkers.hasOwnProperty(i)) {
this.editor.getSession().removeMarker(currentMarkers[i].id);
}
}
// remove background markers except active line marker and selected word marker
currentMarkers = this.editor.getSession().getMarkers(false);
for (const i in currentMarkers) {
if (
currentMarkers.hasOwnProperty(i) &&
currentMarkers[i].clazz !== "ace_active-line" &&
currentMarkers[i].clazz !== "ace_selected-word"
) {
this.editor.getSession().removeMarker(currentMarkers[i].id);
}
}
// add new markers
markers.forEach(
({
startRow,
startCol,
endRow,
endCol,
className,
type,
inFront = false
}) => {
const range = new Range(startRow, startCol, endRow, endCol);
this.editor.getSession().addMarker(range, className, type, inFront);
}
);
}
Show full example Renders a React code editor that takes its syntax highlighting from a third-party library.
Downloads / mo 5.3M
Stars 1.7K
Last release 0.14.1
License MIT Strengths Undoes whole words . Each undo step removes a whole word instead of one letter. Limitations Value must be controlled . Update the value prop from onValueChange on every change. $ npm install react-simple-code-editor@0.14.1 react@19.2.0 react-dom@19.2.0 prismjs@1.30.0 Copy
import { useState } from 'react';
import Editor from 'react-simple-code-editor';
import { highlight, languages } from 'prismjs';
import 'prismjs/components/prism-clike';
import 'prismjs/components/prism-javascript';
export default function App() {
const [value, setValue] = useState('const answer = 42;');
return <Editor value={value} onValueChange={setValue} highlight={code => highlight(code, languages.js, 'javascript')} style={{ fontFamily: 'monospace', fontSize: 14 }} />;
}
react-simple-code-editor examples From open-source projects on GitHub public render() {
return (
<SimpleEditor
className={this.props.classes.root}
value={this.state.code}
onValueChange={this.handleChange}
highlight={highlight}
// Padding should be passed via a prop (not CSS) for a proper
// cursor position calculation
padding={space[2]}
/>
);
}
Show full example Renders a React textarea code editor with built-in syntax highlighting for embeds and forms.
Downloads / mo 779.4K
Stars 579
Last release 3.1.3
License MIT Strengths Highlights code automatically . Colors code without a highlighter supplied by the app. Limitations Next.js needs extra setup . Load the editor in Next.js with a dynamic import and server rendering turned off. $ npm install @uiw/react-textarea-code-editor@3.1.3 react@19.2.0 react-dom@19.2.0 less Copy
import { useState } from 'react';
import CodeEditor from '@uiw/react-textarea-code-editor';
export default function App() {
const [value, setValue] = useState('const answer = 42;');
return <CodeEditor value={value} language="js" onChange={event => setValue(event.target.value)} />;
}
React Textarea Code Editor examples From open-source projects on GitHub const CodeEditor = ({
onChange,
height = 128,
value,
language,
...rest
}: CodeEditorProps) => {
const codeEditor = useMemo(
() => (
<CodeEditorComponent
padding={15}
minHeight={height}
style={{
fontFamily:
'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
fontSize: "16px",
}}
onChange={(event) => onChange?.(event.target.value)}
value={value}
language={language}
{...rest}
/>
),
[value, language],
);
return (
<div style={{ height: `${height}px`, overflow: "auto" }}>{codeEditor}</div>
);
};
Show full example Provides an embeddable browser code editor using a contenteditable host.
Downloads / mo 170.2K
Stars 2.0K
Last release 5.0.0
License MIT Strengths Edits highlighted content directly . Type directly in the highlighted contenteditable host. Includes optional undo history . Undo and redo are enabled through the history option. Limitations Needs a syntax highlighter . Supply a highlighter such as Prism to color the code. Line numbers need an addon . Use the separate line-number package with the current major. $ npm install codejar@5.0.0 prismjs@1.30.0 Copy
import { CodeJar } from 'codejar';
import Prism from 'prismjs';
import 'prismjs/themes/prism.css';
const host = document.body.appendChild(document.createElement('pre'));
host.textContent = 'const answer = 42;';
CodeJar(host, element => {
element.innerHTML = Prism.highlight(element.textContent ?? '', Prism.languages.js, 'js');
});
CodeJar examples From open-source projects on GitHub () => {
Prism.manual = true;
// const highlight = (editor) => {
// editor.innerHTML = Prism.highlight(editor.textContent, Prism.languages.yaml, "yaml");
// Prism.highlightAll();
// };
jar = CodeJar(editor.value!, (elem) => Prism.highlightElement(elem), {
tab: " ",
});
jar.updateCode(props.code);
jar.onUpdate((code) => {
emit("codeChange", code);
});
if (!props.editable) {
editor.value!.setAttribute("contenteditable", "false");
}
}
Show full example Provides a small code editor component with zero dependencies that works in any framework.
Downloads / mo 113.3K
Stars 187
Last release 1.1.1
License MIT Strengths Plugins shape each edit . Each plugin receives the textarea state and returns the next text and selection. Limitations Small documents only . Large documents, multicursor editing, rich text, and server rendering are out of scope. $ npm install yace@1.1.1 Copy
import { Yace } from 'yace';
import { code } from 'yace/highlighters/code';
import { history, tab, preserveIndent } from 'yace/plugins';
const host = document.body.appendChild(document.createElement('div'));
new Yace(host, { value: 'const answer = 42;', lineNumbers: true, highlighters: [code()], plugins: [history(), tab(), preserveIndent()] });
Yace examples From open-source projects on GitHub () => {
const editor = editorRef.current
if (!editor || editor.value === value) {
return
}
editor.update({ value })
}
Overlays Prism-highlighted code on a textarea and splits it into lines for line numbers and partial updates.
Downloads / mo 107.5K
Stars 161
Last release 5.4.0
License MIT Strengths Works on mobile . Editing works in mobile browsers as well as on the desktop. Ships ready-made setups . Each setup imports its styles, extensions, and language behavior in one call. $ npm install prism-code-editor@5.4.0 Copy
import { basicEditor } from 'prism-code-editor/setups';
import 'prism-code-editor/prism/languages/markup';
const host = document.body.appendChild(document.createElement('div'));
host.style.display = 'grid';
basicEditor(host, { language: 'html', theme: 'github-dark', value: '<h1>Hello world</h1>' });
prism-code-editor examples From open-source projects on GitHub initEditor(): PrismEditor {
const editor = createEditor(this.editorContainer.nativeElement, {
value: this.code(),
language: this.language(),
lineNumbers: false,
wordWrap: true,
readOnly: this.readonly(),
onUpdate: (code: string) => {
this.code.set(code);
},
});
editor.addExtensions(
copyButton(),
matchBrackets(true),
highlightBracketPairs(),
editHistory()
);
this.code.subscribe(() => {
this.editor?.update();
});
return editor;
}
Show full example