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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-online-editor

v1.0.0

Published

Write your React components in React!

Downloads

2

Readme

react-online-editor

Package CI npm version Storybook

Description

Write your own React Components without using Desktop IDE in React!

react-online-editor is a React component library that provides the ability to code and compile your React codes in a Web environment. It's not as powerful as CodeSandbox. It uses codemirror library to provide the amazing code editor UI.

NOTE: Currently, dependency import is not supported yet

Why react-online-editor

  • The library gives the user a lot of flexibility since it just provided the code editor and compiling ability using Babel.
  • You can choose your own theme for the codemirror editor or create your own too.
  • It's lightweight and has a minimal configuration.

How it works

Using a similar idea to Webpack, it transpiles & wraps your code into a single factory function. It uses the global variable window in order to store the dependency map for dependency resolution. Everything is done in Javascript, and you can modify it easily.

Requirements

  • Peer Dependencies: npm install react react-dom react-codemirror2 codemirror

Links

Installation

npm install react-online-editor

How to use

Bundler

Please refer to documentation for more detail

React Editor

Before using it, you need to run npm install @babel/preset-react.

| Props | Type | Description | | -------------------------- | ----------- | ----------- | | code | Code - { code: string, files: Dictionary } | Your React code, represented as a JSON object consisted of app (the main file) and files (file container in form of JSON object) | | currentFile | string | The current selected file (app, etc) | | storageKey | string | The localStorage key for storing the code | | codeEditorContext | string | The window key for storing the bundled code | | viewer | ReactRef | React reference object for rendering the React component |

Sample code:

import { useRef } from "react";
import { ReactEditor } from "react-online-editor";

function YourReactComponent() {
    const viewer = useRef();
    ...
    const code = { app: "function App() {\n  return <div>123</div>;\n}", files: {} };
    return <ReactEditor
            code={code}
            currentFile="App"
            viewer={viewer}
            codeEditorContext="my-react-editor" />;
}

Vue Editor

Before using it, you need to run npm install @vue/babel-plugin-jsx @vue/babel-preset-jsx @vue/babel-sugar-v-on.

| Props | Type | Description | | -------------------------- | ----------- | ----------- | | code | Code - { code: string, files: Dictionary } | Your Vue code, represented as a JSON object consisted of app (the main file) and files (file container in form of JSON object) | | currentFile | string | The current selected file (app, etc) | | storageKey | string | The localStorage key for storing the code | | codeEditorContext | string | The window key for storing the bundled code | | viewerId | string | Document ID for rendering the Vue component |

Sample code:

import { useRef } from "react";
import { VueEditor } from "react-online-editor";

function YourReactComponent() {
    ...
    const code = { app: 'const App = {\n  methods: {\n    test() {\n      console.log("hi");\n    }\n  },\n  render() {\n    return <button onClick={this.test}>Vue 3.0</button>;\n  },\n};', files: {} };
    return <VueEditor
            code={code}
            currentFile="App"
            viewer="app"
            codeEditorContext="my-react-editor" />;
}

Customizable Editor

Doesn't like the theme or want to support another framework/language? You can use CustomizableEditor

| Props | Type | Description | | -------------------------- | ----------- | ----------- | | code | Code - { code: string, files: Dictionary } | Your Vue code, represented as a JSON object consisted of app (the main file) and files (file container in form of JSON object) | | currentFile | string | The current selected file (app, etc) | | storageKey | string | The localStorage key for storing the code | | theme | string | CodeMirror theme | | keyMap | string | CodeMirror key map | | runCode | function(code: Code) | Process your code |

Sample code: ReactEditor

Use Cases

React-related Coding Guides

With react-online-editor, you can make your coding guides more interactive since you can try to code while learning. The idea is similar to Tour Golang and Svelte Tutorial.

Simple Code Snippet Server

Similar to CodeSandbox embeddable iframe, you can also create your own code snippet server.

Test & Experimentation

Using this library, you can test or experiment on a certain code without the need to wait for bundling.