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-medium-editor-es6

v0.1.0

Published

React wrapper for medium-editor

Downloads

171

Readme

react-medium-editor-es6

ES6 version of React wrapper for medium-editor

This repository is a fork of the original react-medium-editor react-wrapper by @wangzuo

Installation

npm install react-medium-editor-es6 --save

However, since this package exports an ES6 class, you'll need to load this with an appropriate handler (e.g babel). Here's an example of how you can do that if you're using webpack. Doing this with browserify is similar:

module.exports = {
    module: {
        loaders: [
            {
                test: /\.js$/,
                include: ([
                    /react-medium-editor-es6\/src/,
                    path.resolve(__dirname, 'src'),
                ]),
                loader: 'babel',
            }
        ]
    }
}

And you're good to go. This package is very little amount of code, so if you find some feature missing, just clone this repostory and npm link this package. No pesky rebuilding required for development.

Usage

import React, {
    Component,
} from 'react';

// load theme styles with webpack
import 'medium-editor/dist/css/medium-editor.css';
import 'medium-editor/dist/css/themes/default.css';

import MediumEditor from 'react-medium-editor-es6';

class App extends Component {
    render() {
        return (
            <div>
                <MediumEditor
                    tag='pre'
                    flushEditorDOM={shallFlushEditorDOM}
                    text={'content'}
                    options={
                        ...mediumOptions,
                    }
                    onChange={handleChangeEditorContent}
                />
            </div>
        );
    }
}

Props

  • tag (string): Name of the HTML element which will be created for this component. In the above example, a <pre></pre> element will be creaed and handed over to Medium editor
  • text (string): The content of the editor. It can be HTML content
  • options (object): Medium editor options
  • onChange (function): Callback which will be called when user changes the editor content
  • flushEditorDOM (boolean): An interesting problem I faced when no using any internal state was that normal Undo operation won't work, since react would re-render the component, set new editor content, and for the browser, the undo is lost. So because I am lazy, I decided to not write to DOM at all. I mean it does write to DOM, but not to the knowledge of react. This means that props.text don't change the actual content of the Editor. To do so, you need to pass flushEditorDOM=true. There's probably a better way to do this, feel free to fork and create a PR may be; or you can wait for me to solve it which might or might not happen depending on whether I see it as a problem at some point or not.

Why the fork?

Well, mostly because:

  • I am a prick. I should have modified the code and created a pull request instead, but I didn't. Because I am prick.
  • I had some propblems integrating the original component in my redux app, had to change some stuff and I didn't like all the building that was required. ES6 modules will be here soon anyway and it's much easier to work with them directly rather than requiring to build in 2 places (first the component, then the app) imo, so I forked it to an ES6 version
  • This component has some differences than the original component. We strictly use props, no internal state, and pay for the consequences too.

License

MIT