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

@167pluto/rte

v1.0.1

Published

Pluto Rich Text Editor

Downloads

1

Readme

Creating an editor and using it

To create and use the editor, import PlutoRTE and DEFAULT_EDITOR_STATE, and provide the necessary props:

import { PlutoRTE, DEFAULT_EDITOR_STATE } from '@167pluto/rte';
import axios from '~/utils/axios';

const SomeComponent = () => {
  const editorRef = useRef < null > null;

  return <PlutoRTE editorRef={editorRef} initialEditorState={DEFAULT_EDITOR_STATE} axiosInstance={axios} mediaUploadEndpoint={'/media'} />;
};

Generating rich text editor's JSON

To generate the editor's JSON representation, use the generateJSON function:

import { generateJSON } from '@167pluto/rte';

const SomeComponent = () => {
  const editorRef = useRef < null > null;

  const json = generateJSON(editorRef);

  return <PlutoRTE editorRef={editorRef} initialEditorState={DEFAULT_EDITOR_STATE} axiosInstance={axios} mediaUploadEndpoint={'/media'} />;
};

Converting Editor JSON to HTML

To convert the editor's JSON output to HTML, use the convertToHTML function:

import { convertToHTML } from '@167pluto/rte';

const SomeComponent = () => {
  const htmlString = convertToHTML(editorJSON);

  return <div dangerouslySetInnerHTML={{ __html: htmlString }}></div>;
};

Displaying Embedded Tweets

To display embedded Twitter posts, add the following useEffect hook to your component:

import { convertToHTML } from '@167pluto/rte';

const SomeComponent = () => {
  const htmlString = convertToHTML(editorJSON);

  useEffect(() => {
    const script = document.createElement('script');
    script.src = 'https://platform.twitter.com/widgets.js';
    script.async = true;
    document.body.appendChild(script);

    return () => {
      document.body.removeChild(script);
    };
  }, [htmlString]);

  return <div dangerouslySetInnerHTML={{ __html: htmlString }}></div>;
};

Toolbar options

The toolbar in Pluto Rich Text Editor is fully customizable. Here's the default configuration:

const toolbarOptions = {
  normal: true,
  heading1: true,
  heading2: true,
  heading3: true,
  heading4: true,
  heading5: true,
  heading6: true,
  bulletList: true,
  numberedList: true,
  bold: true,
  italic: true,
  underline: true,
  strikethrough: true,
  link: true,
  subscript: true,
  superscript: true,
  image: true,
  leftAlign: true,
  rightAlign: true,
  centerAlign: true,
  justifyAlign: true,
  startAlign: true,
  outdent: true,
  indent: true,
  endAlign: true,
  twitter: true,
  youtube: true
};

By default, all tools are enabled. To exclude specific tools, set their values to false in the toolbarOptions prop:

import { PlutoRTE, DEFAULT_EDITOR_STATE } from '@167pluto/rte';
import axios from '~/utils/axios';

const SomeComponent = () => {
  const editorRef = useRef < null > null;

  return (
    <PlutoRTE
      editorRef={editorRef}
      initialEditorState={DEFAULT_EDITOR_STATE}
      axiosInstance={axios}
      mediaUploadEndpoint={'/media'}
      toolbarOptions={{
        header1: false,
        twitter: false
      }}
    />
  );
};

In toolbarOptions prop just send tools that you want to be excluded. More tools are on the way.