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-easy-wysiwyg

v2.0.0

Published

A simple, convenient frontend for tiptap.

Downloads

9

Readme

React Easy WYSIWYG

A simple, convenient frontend for tiptap, which itself builts upon ProseMirror. Outputs HTML or JSON.

Icons from Lucide icons.

screenshot from the React-easy-wysiwyg demo

Implemented modules are:

  • The entire TipTap Starterkit
  • Link
  • Underline

Why?

Tiptap, by design, only provides the barebones tools to built a text editor. For my personal website I built a wrapper, and decided I might as well release it for others to use.

Demo

To view the demo, clone the repo, run npm i to install dependencies and then run npm run demo.

Usage

This package is ESM only, and is built targetting ES2019.

npm install react-easy-wysiwyg

import Editor from "react-easy-wysiwyg";

// Assuming you can import CSS directly, like with Vite, CRA or Next.js
import "react-easy-wysiwyg/styles.css";

const App = () => {

  return (<>
    <h1>My wonderful app</h1>
    <Editor />
  </>)
}

Next.js

Due to the inherently large size of this module, it's highly recommended to lazy load the module in your page, with next/dynamic for example.

If using the app directory, available in Next.js 13, you'll need to mark it's parent as a Client Component.

API

| Prop | Type | Default | Description | | --------------- | -------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | content | object | string | | The content, either a JSON object as exported by tiptap, or an HTML document | | onSave | (string \| object) => {} | | On save, this function receives one argument, the content. This is either HTML (string) or an object, based on the exportHTML prop | | exportHTML | boolean | false | If set to true, onSave receives an HTML string instead of an object | | editable | boolean | true | If set to false, the editor will render content without editing capabilities. It will still import all moduled needed for editing, however, so a dedicated solution is preferred. | | showWordCount | boolean | true | Whether or not to show the wordcount in the lower right corner | | className | string | | Allows passing a custom className to the wrapper (which already has the rew-wrapper class, as well as some default styling) | | buttons | object | buttons {} | Allows customizing displayed buttons. See buttons | | labels | object | labels {} | Allows changing displayed text. See labels | | onLinkClick | (e) => {} | See description | By default, ignores clicked links, unless cmd or ctrl is pressed. |

labels

{
  url: "URL",
  save: "Save",
}

Customizing

There are several options to customize the look of the Editor. For larger changes, you're better off building an interface for tiptap yourself.

Styles

This is the easiest, and the one you'll probably always want. It can be as simple as redefining CSS Custom properties.

.rew-container {
  /* Styling defaults */
  --rew-background-color: #282336;
  --rew-color: #fff;

  /* Styling inline code */
  --rew-inline-code-background-color: #000;
  --rew-inline-code-color: #cfcfcf;
  --rew-inline-code-font: monospace;

  /* Styling code blocks */
  --rew-code-background-color: #000;
  --rew-code-color: #cfcfcf;
  --rew-code-font: monospace;

  /* Styling the borders */
  --rew-accent: #ff7edb;
  /* Color of menu seperators */
  --rew-seperator: rgba(255,126,219,.2);
  /* Color of indicators for quote blocks */
  --rew-highlight: rgba(255,126,219,.2);
  /* Background color of 'active' buttons */
  --rew-selected: rgba(255,126,219,.2)
}

@media (prefers-color-scheme: dark) {
  .rew-container {
    /* Same, but for dark mode users */
  }
}

The module is built using CSS Modules, so naming collissions are unlikely. Several 'plain' namespaced classNames are exposed for further styling:

.rew-container {
  /* The outermost <div>, containing both the menu and the wrapper */
}
.rew-menu {
  /* The menu bar at the top, containing all buttons */
}
.rew-wrapper {
  /* The <div> wrapping the content-editable <div> rendered by tiptap */
}

On top of this, the .ProseMirror class can be used for styling the content itself. By default, your 'normal' styles are inherited.

Buttons

This module allows for custom buttons if you don't like the look of the default icons from Lucide icons. To do so, just provide a buttons prop to the editor:

// All possible options. You only have to provide the ones you want to override.
const altButtons = {
  bold: "B",
  italic: "I",
  underline: "U",
  strikethrough: "S",
  heading1: "H1",
  heading2: "H2",
  heading3: "H3",
  heading4: "H4",
  heading5: "H5",
  heading6: "H6",
  code: "C",
  bulletList: "L",
  orderedList: "LO",
  codeBlock: "CB",
  blockquote: "BQ",
  horizontalRule: "M",
  undo: "U",
  redo: "R",
  link: "L",
  unlink: "UL",
  save: "Sa",
};

<Editor buttons={altButtons} />

If any alt is not defined, the default icon will render. To disable, just set it to any falsy value like false or null.

The content can be any node that react can render (which is basically anything). No logic for rendering is provided, so if using React components, you must pass the rendered result, not the component itself:

const Bold = () => <span>B</span>;
const Italic = () => <span>I</span>;

<Editor buttons={{
  bold: <Bold />, // ✅
  italic: Italic, // ❌
}} />