npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-codemirror-editor

v0.7.1

Published

A modular, extensible React code editor built on CodeMirror 6 with first-class JSON support.

Readme

React Code Editor

npm downloads license

A modern, extensible CodeMirror 6–based React code editor with TypeScript support, built-in language plugins, JSON schema validation, diagnostics, search, and a powerful controller API.

Designed to scale from simple embeds to multi-language platforms.


Features

  • Built on CodeMirror 6
  • JSON schema validation (AJV-powered)
  • JavaScript & TypeScript support
  • Diagnostics, autocomplete & hover
  • Powerful search
  • Controller API
  • Built-in light & dark themes
  • Fully customizable themes
  • Language-agnostic formatting
  • Multi-language plugin architecture

Install

npm install react-codemirror-editor
npm install react react-dom

Optional (JSON support):

npm install @codemirror/lang-json codemirror-json-schema ajv

Optional (JavaScript / TypeScript support):

npm install @codemirror/lang-javascript

Basic Usage

JSON

import { CodeEditor } from 'react-codemirror-editor';

export function Example() {
    return <CodeEditor language="json" defaultValue="{}" />;
}

JavaScript

import { CodeEditor } from 'react-codemirror-editor';

export function Example() {
    return <CodeEditor language="js" defaultValue="const message = 'Hello World';" />;
}

TypeScript

import { CodeEditor } from 'react-codemirror-editor';

export function Example() {
    return <CodeEditor language="ts" defaultValue="interface User { name: string }" />;
}

Controlled vs Uncontrolled

// Uncontrolled
<CodeEditor language="json" defaultValue='{"name":"John"}' />

// Controlled
const [value, setValue] = useState('{}');
<CodeEditor language="json" value={value} onChange={setValue} />;

Do not pass both value and defaultValue.


Controller API

Pass controllerRef for programmatic control.

Methods

copy()
format(formatter)
foldAll()
unfoldAll()
openSearch()
closeSearch()
findNext()
findPrev()
replace(string)
replaceAll(string)
getValidation()
getDiagnostics()

Formatting Example

controllerRef.current?.format((value) =>
    JSON.stringify(JSON.parse(value), null, 2),
);
  • No built-in formatter
  • Works with Prettier or custom logic
  • Fully language-agnostic

Search

<CodeEditor
    language="json"
    searchOptions={{ top: true, caseSensitive: false }}
/>

Validation & Diagnostics

const validation = controllerRef.current?.getValidation();
const diagnostics = controllerRef.current?.getDiagnostics();

Disable diagnostics for any language:

languageOptions={{ json: { diagnostics: false } }}

JSON

Supports:

  • Syntax errors
  • Schema validation (if schema provided)

JavaScript / TypeScript

Supports:

  • Syntax diagnostics
  • Snippet autocomplete
  • Global scope completions
  • Custom schema-based autocomplete
  • Schema hover tooltips

Language Support

Current: JSON, JavaScript, TypeScript
Planned: Python, HTML, CSS


Language Configuration

Common Options

These options are available for all supported languages.

| Option | Type | Default | Description | | -------------- | ------- | ---------------- | ---------------------------------------- | | diagnostics | boolean | true | Enable syntax diagnostics | | gutter | boolean | true | Show error gutter | | hover | boolean | true if schema | Enables hover tooltips from schema | | autocomplete | boolean | true if schema | Enable autocompletion |

JSON

<CodeEditor
    language="json"
    languageOptions={{
        json: {
            schema,
            diagnostics: true,
            gutter: true,
        },
    }}
/>

JSON Options

| Option | Type | Default | Description | | -------------- | ------- | ---------------- | ---------------------------------------- | | schema | object | undefined | Schema for validation, completion, hover | | schemaLint | boolean | true if schema | Enables schema-based validation |

JavaScript / TypeScript

<CodeEditor
    language="js"
    languageOptions={{
        "js": {
            schema,
            diagnostics: true,
            gutter: true,
            autocomplete: true,
            jsx: true
        },
    }}
/>

JavaScript / TypeScript Options

| Option | Type | Default | Description | | -------------- | -------------- | ---------------- | ----------------------------------------------- | | schema | Completion[] | [] | Custom schema used for JavaScript autocomplete | | jsx | boolean | false | Enable JSX syntax support |

Without a schema, syntax diagnostics still work.


Read Only

<CodeEditor language="json" value={json} readOnly={true} />

Editor Options

Configure the editor experience with a set of customizable editor options.

<CodeEditor
    language="json"
    editorOptions={{
        line_wrapping: true,
        indent_unit: 4,
        indent_with_tab: true,
        ...
    }}
/>

Available Options

| Option | Type | Default | Description | | ------- | ---- | :-----: | ----------- | | line_numbers | boolean | true | Display line numbers. | | line_wrapping | boolean | false | Wrap long lines instead of enabling horizontal scrolling. | | highlight_active_line | boolean | true | Highlight the active line. | | highlight_selection_matches | boolean | true | Highlight all occurrences of the current selection. | | fold_gutter | boolean | true | Display the code folding gutter and enable code folding. | | bracket_matching | boolean | true | Highlight matching brackets while the cursor is adjacent to them. | | auto_close_brackets | boolean | true | Automatically insert matching brackets and quotes while typing. | | indent_on_input | boolean | true | Automatically re-indent lines as you type. | | indent_with_tab | boolean | true | Allow the Tab key to indent the current line or selected lines. | | indent_unit | number | 2 | Number of spaces used for indentation when tabs are disabled. | | allow_multiple_selections | boolean | true | Enable multiple cursors and selections using Ctrl/Cmd + D. |


Layout

Set height via CSS:

.cm-editor-container {
    min-height: 200px;
}

.cm-editor-container,
.cm-editor-container .cm-editor {
    width: 100%;
    height: 100%;
}

Themes

import { Themes } from 'react-codemirror-editor';
<CodeEditor theme={Themes.dark} />;

Available Themes

| Category | Themes | | --------- | --------------------------------------------------------------------------------------------------------------------------------------- | | Light | light, ayu_light, clouds_light, espresso_light, noctis_lilac_light, rose_pine_dawn_light, smoothy_light, tomorrow_light | | Dark | dark, barf_dark, cobalt_dark, cool_glow_dark, dracula_dark |

Custom Theme

Create a custom editor theme using a simple configuration object.

const customTheme = {
    dark: true,
    colors: {
        background: '#1b1414',
        foreground: '#f2eaea',
        cursor: '#ff6b6b',
        selection: '#5a2424',
        activeLineBackground: '#2b1c1c',
    },
    syntax: {
        keyword: '#ff6b81',
        string: '#ffb86c',
        function: '#ff8a65',
        comment: '#8c6b6b',
    },
};

<CodeEditor theme={customTheme} />

Theme Options

| Section | Options | | ------------ | ------- | | General | dark | | Colors | background, foreground, cursor, selection, gutterBackground, gutterForeground, lineNumber, activeLineNumber, activeLineBackground, activeLineGutter | | Syntax | keyword, string, number, comment, variable, function, property, type, class, tag, attribute, operator, punctuation |


Architecture

  • Modular & composable
  • Optional diagnostics, hover, completion, search
  • Language extensions isolated per configuration
  • Designed for extensibility

Roadmap

  • HTML support
  • CSS support
  • Python support
  • Extension injection API
  • Presets
  • Diff mode

License

MIT License © 2025 Mihir Mistry


Acknowledgements

Some themes are inspired by Thememirror by Vadim Demedes (MIT License).