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-prosemirror

v0.2.1

Published

A React component for ProseMirror

Downloads

104

Readme

react-prosemirror

An unofficial React component for ProseMirror. Build Status

Hello World

import ProseMirror from 'react-prosemirror'

const Hello = React.createClass({
  getInitialState() {
    return {value: 'Hello World!'}
  },
  render() {
    return <ProseMirror value={this.state.value} onChange={this.onChange} options={{docFormat: 'html'}} />
  },
  onChange(value) {
    this.setState({value})
  }
})

Installation

Via NPM (note that you need to install ProseMirror yourself)

npm install --save react-prosemirror prosemirror

If your target environment doesn't natively support Object.assign, you may need to use some sort of polyfill such as babel-polyfill.

Usage

The intent is to provide an API compatible with standard React form elements. react-prosemirror supports defaultValue, value and onChange props as well as valueLink. It additionally supports an options prop which is passed directly to the ProseMirror constructor.

The ProseMirror instance is stored on the component instance as pm. You can gain access to it by putting a ref prop on the component.

render() {
  return <ProseMirror value={value} onChange={callback} ref="editor" />
},
someFunc(posA, posB) {
  this.refs.editor.pm.setSelection(posA, posB)
}

Finally, instances have a getContent method which defaults to the selected docFormat.

Options

react-prosemirror simply passes options into ProseMirror. It will not automatically load other modules. For example, if you wish to use the menubar option or markdown format, you'll need to import those modules in addition to adding the appropriate options.

import 'prosemirror/dist/markdown'
import 'prosemirror/dist/menu/menubar'

Formats

options.docFormat is used to determine the type of value returned to the onChange callback as well as what is expected to be in the value prop.

react-prosemirror will attempt to control the component in the spirit of standard React form elements (see: Why Controlled Components?). To avoid thrashing ProseMirror, it will only call setContent when the new value is not strictly equal (===) to the last value pulled from ProseMirror. This should work for most cases, but be aware of that if you're using a complex type such as json.

Project Status

I would consider this library largely complete within its scope, though clearly not proven in a production setting. I'm open to refinements, especially around the interaction of docFormat and controlled values.

I intend to track ProseMirror API changes as needed.