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

v0.5.2

Published

react wrapper for ckeditor5

Downloads

25

Readme

The latest major iteration of CKEditor provides a class based, MVC, imperative API for creating and updating the editor.

While powerful, it doesn't fit well into a declarative React.js app.

react-ck5 provides two main apis for defining an editor:

  • ClassicBasic: a basic editor with default styling and features
  • CustomEditor: build your own editor, reuse components from your app

ClassicBasic

This editor is very easy to use, and supports selecting the toolbar buttons.

import ClassicBasic from 'react-ck5/lib/ClassicBasic';

class Editor extends React.Component {
  state = {
    html: `<p>Hello, <strong>world</strong>!</p>`,
  }
  render() {
    return (
      <ClassicBasic
        value={this.state.html}
        onChange={html => this.setState({ html })}
      />
    );
  }
}

You can pass a custom toolbar. This shows the default:

<ClassicBasic
  toolbar={['bold', 'italic', 'link', 'numberedList', 'bulletedList', 'blockQuote', 'headings']}

value must be a string, but it can be the empty string.

Once the editor is loaded with the initial value if the editor interprets the value differently from the string you passed, onChange will be called - even before user interaction. In this special case, the second argument to onChange will be an object with the property isIntial: true.

<ClassicBasic
  value={this.state.html}
  onChange={(html, event) => {
    if (event.isInitial) {
      // ignore the initial update
      return;
    }
    this.setState({ html });
  }}

It's recommended that you don't ignore the initial update, however you may wish to handle it specially, e.g. not setting a 'dirty' flag in state for this update.

onChange always receives an event object as the second argument, however currently it only has the one property mentioned above which will be true or false.

CustomEditor

Smaller bundle size, more customization options, fully controlled editor state.

TODO: write docs once api stabilizes.

props.editorState and props.onStateChange

All editors also support two props for controlling the state (other than the value) of the editor. Usually you'll pass null for the editorState prop on the initial render, and then your onStateChange will be called with all of the state properties.

We'll use a small helper to make the deep update syntax nicer.

import { update } from 'object-path-immutable';
  state = { editorState: null }
  render() {
    return (
      <div>
        <ClassicBasic
          value={/* ... */}
          onChange={/* ... */}
          editorState={this.state.editorState}
          onStateChange={editorState => this.setState({ editorState })}
        />
        <button
          // prevent editor losing focus
          onMouseDown={e => e.preventDefault()}
          onClick={() => {
            this.setState(s => update(s, 'editorState.bold.value', value => !value));
          }}
        >
          Toggle bold
        </button>
      </div>
    );
  }

When the button is clicked, bold will be toggled in the editor. Aside from value, all of the commands take an isEnabled property which will disable the functionality, and in the ClassicBasic editor, any UI controls for that feature.