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

v1.0.3

Published

A React, DraftJS-based WYSIWYG editor

Downloads

19

Readme

CircleCI

React Drafts

React-based WYSIWYG editor built using DraftJS. Aim is to support the most commonly requested editor features, plus some uncommonly found features like support for tables.

react-drafts-features

Installation

$ npm install react-drafts

Use

This package includes a Common module build at /lib and a UMD bundle in /dist. Most applications will use the Common build by importing ReactDrafts as below.

## editor parent component
import React, { Component } from 'react';
import ReactDrafts from 'react-drafts';

class MyEditor extends Component {
  ...

  render() {
    return (
      <div>
        <button onClick={this.handleSave}>Save</button>
        <button onClick={this.handleClear}>Clear</button>
        <ReactDrafts
          onFileUpload={this.handleFileUpload}
          exportTo="raw"
        />
      </div>
    );
  }
}

To include styles, just import the css file from /dist, ie:

## manifest.css
@import <path_to>/node_modules/react-drafts/dist/react-drafts.css

See the demo directory for a more complete example. Demo contains a sample editor parent container that instantiates the ReactDrafts component and passes in props.

Public methods

| Name | Description | | --- | --- | | focus | Focus the editor. | | save | Save content to whatever format is specified in the exportTo prop (see below). Returns a promise, and resolves with content or error message if an error is thrown. | | clear | Clear content from the editor. Returns a promise. |

Props

| PropName | Type | Description | Default value | | --- | --- | --- | --- | | content | string (html string or stringified JSON for raw) | HTML or raw content | none | | placeholder | string | Editor placeholder message | 'Enter text here...' | | spellcheckEnabled | boolean | Enable browser spellcheck (behavior is dependent on user settings) | true | | customControls | array (of strings) | If you wish to exclude any of the default options, do so by passing an array of the control names that you do wish to include as customControls prop. | defaults (see list below) | | detachToolbarOnScroll | boolean | Whether to detach the toolbar on scroll. Fixes to top of viewport for better user experience on longer posts. | true | | allowPhotoLink | boolean | Whether to allow users to wrap uploaded photos in links. | false | | allowPhotoSizeAdjust | boolean | Whether to allow users to adjust the size of uploaded images. | false | | maxImgWidth | number | Setting this param will not constrain image upload sizes, but will warn users on photo upload that their image is too large and they need to size down below this max size. | none | | linkInputAcceptsFiles | boolean | If you'd like to give users the option to add downloadable file links inlined, in addition to (or instead of) as block components with optional captions, pass true. | false | | onFocus | function | Respond to editor focus event. | no-op | | onBlur | function | Respond to editor blur event. | no-op | | onFileUpload | function, *required | Respond to file upload event. Hook for saving file to server or cloud service. | none, required | | exportTo | string ('html' or 'raw'), *required | Import/Export format. Raw option exports DraftJS raw format, which can be parsed into markdown or other format. | none, required |

Toolbar controls

headings
bold
italic
underline
strikethrough
quotes
bulletList
orderedList
alignLeft
alignCenter
alignRight
divider
link
table
file
photo
rich

Developing and testing

To get started, clone down the repo and $ npm install.

There's a development server that serves a demo project that consists of a parent component that renders the exported ReactDrafts module. The server has built-in hot-reloading. To use, run:

$ npm start
## editor is running at localhost:3000

Tests can be run both in node or in the browser:

## Node:
$ npm test

## Browser:
$ npm run test:browser

Issues and Contributions

Contributions are welcome! We will be using Github issues to track feature requests and other proposals. Enhancements and bugs will be tagged accordingly.

If you find a bug, please report using the following format:

## What I was trying to do:

## Expected behavior:

## Actual behavior:

## OS/platform, browser and browser version

## Reproducible case and/or test (if applicable)