Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mui-tiptap-editor

Package Overview
Dependencies
Maintainers
0
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mui-tiptap-editor

Easy to use Tiptap WYSIWYG rich text editor using Material UI (MUI) for React

  • 0.11.6
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
139
decreased by-87.33%
Maintainers
0
Weekly downloads
 
Created
Source

mui-tiptap-editor

A customizable and easy to use Tiptap styled WYSIWYG rich text editor, using Material UI.

NPM Version Language Build

Table of Contents

Demo

Screenshot

Installation


npm install mui-tiptap-editor

or


yarn add mui-tiptap-editor

Please note that @mui/material (and their @emotion/ peers) are peer dependencies, meaning you should ensure they are installed before installing mui-tiptap-editor.

npm install @mui/material @emotion/react @emotion/styled

or

yarn add @mui/material @emotion/react @emotion/styled

Get started

Simple usage

import { TextEditor, TextEditorReadOnly } from 'mui-tiptap-editor';
import { useState } from "react";

function App() {
  const [value, setValue] = useState<string>("");

  const handleChange = (newValue: string) => setValue(newValue);

  return (
    <div>
      <TextEditor value={value} onChange={handleChange} />
      {value && <TextEditorReadOnly value={value} />}
    </div>
  );
}

Using mentions

import { TextEditor, ITextEditorOption } from 'mui-tiptap-editor';

const mentions: ITextEditorOption[] = [
  { label: "Lea Thompson", value: "id1" },
  { label: "Cyndi Lauper", value: "id2" },
  { label: "Tom Cruise", value: "id3" },
];

const currentUser: ITextEditorOption = mentions[0];

function App() {
  return (
    <TextEditor mentions={mentions} user={currentUser} userPathname="/profile" />
  );
}

Image upload

Here is the corrected English version:

<ul>
  <li>The image can be uploaded to the server via an API call or inserted directly into the content as a base64 string.</li>
  <li>The image can be uploaded using the upload button, or pasted or dropped.</li>
  <li>Add or modify the alt text and the caption (title) of the image.</li>
  <li>Delete the selected image using the `Delete` key on the keyboard.</li>
</ul>
// Example of an API upload using fetch
// The returned data must be the image URL (string) or image attributes (object) such as src, alt, id, title, etc.
const uploadFile = async (file: File) => {
  const formData = new FormData();
  formData.append("file", file);
  const response = await fetch("https://api.escuelajs.co/api/v1/files/upload", {
    method: "POST",
    body: formData,
  });
  const data = await response.json();
  // or return data.location
  return { id: data.filename, src: data.location };
};

function App() {
  return (
    <TextEditor
      uploadFileOptions={{
        uploadFile, // the image is stored and used as base64 string if not specified
        maxSize: 5, // max size to 10MB if not specified
        maxFilesNumber: 2,  // max 5 files if not specified
        allowedMimeTypes: ['image/jpeg', 'image/png', 'image/jpg'], // all image types if not specified
        imageMaxWidth: 400, // default to 1920
        imageMaxHeight: 400, // default to 1080
      }}
    />
  );
}

See here for more examples that use TextEditor.

Read only

  1. If using the editor
import { TextEditorReadOnly } from 'mui-tiptap-editor';

<TextEditorReadOnly value="<h1>Hello word!</h1>" />
  1. If you only need to display the value without using the editor, you can use this library: tiptap-parser. Example: The editor is used in the back office, but the content must be displayed on the website.
<TiptapParser content="<h1>Hello world</h1>" />

Customization

Toolbar

Can display the menus as required.

  <TextEditor toolbar={['bold', 'italic', 'underline']} />

Override labels

  <TextEditor
    labels={{
      editor: {
        editor: "Editeur",
        preview: "Aperçu"
      },
      toolbar: {
        bold: "Gras",
        upload: "Ajouter une image",
        // ...
      },
      headings: {
        h1: "En-tête 1",
        // ...
      },
      table: {
        table: "Tableau",
        deleteColumn: "Supprimer la colonne",
        // ....
      },
      link: {
        link: "Lien",
        // ...
      },
      youtube: {
        link: "Lien",
        insert: "Insérer la vidéo Youtube",
        title: "Insérer une vidéo Youtube",
      },
      upload: {
        fileTooLarge: "Fichier trop volumineux",
        // ...
      }
    }}
  />

Styles

Root styles
import './index.css';

<TextEditor
  value="<p>Hello word!</p>"
  rootClassName="root"
/>
/* ./index.css */
.root {
  background-color: #fff;
}
.root  .MuiTab-root.Mui-selected {
  background-color: yellow;
}
Each element styles
<TextEditor
  value="<p>Hello word!</p>"
  label="Content"
  tabClassName="bg-black"
  labelClassName="text-sm"
  inputClassName="border border-gray-200"
  toolbarClassName="bg-gray-500"
/>
}

Props

propstypeDefault valueDescription
toolbarstring[]heading, bold, italic, strike, link, underline, image, code, orderedList, bulletList, align, codeBlock, blockquote, table, history, youtube, color, mentionThe list of the menu buttons to be displayed
placeholderstringemptyinput placeholder
labelstringemptyinput label
errorstringemptyError message to display
withFloatingMenubooleanfalseShow or hide the floating menu
withBubbleMenubooleantrueShow or hide the bubble menu
inputClassNamestringemptyOverride input styles
toolbarClassNamestringemptyOverride the toolbar menu styles
tabsClassNamestringemptyOverride the tabs (preview, editor) styles
tabClassNamestringemptyOverride the tab (preview or editor) styles
errorClassNamestringemptyOverride the error message styles
rootClassNamestringemptyOverride the main container styles
labelClassNamestringemptyOverride the label styles
bubbleMenuToolbarstring[]['bold', 'italic', 'underline', 'link']Similar to toolbar props
floatingMenuToolbarstring[]['bold', 'italic', 'underline', 'link']Similar to toolbar props
mentionsITextEditorOption[]undefinedList of users to be mentioned when entering or selecting @
userITextEditorOptionundefinedCurrent user
valuestringemptyValue of the input
onChange(value: string) => void-Function to call when the input change
userPathnamestring/userURL pathname for the mentioned user (eg: /user/user_id)
labelsILabelsnullOverride labels, for example using i18n
disableTabsbooleanfalseIf true, the Editor/Preview tabs are hidden.
toolbarPositiontop or bottombottomPosition of the toolbar
idstringemptyUsed if using multiple editors on the same page, to identify uniquely each editor
uploadFileOptionsImageUploadOptionsnullOverride image upload default options like max size, max file number, ...
...all tiptap featuresEditorOptionsemptyCan access to all tiptap useEditor props

See here how to use all the TextEditor props.


ImageUploadOptions

propstypeDefault valueDescription
uploadFilefunctionundefinedan API call to your server to handle and store the image
maxSizenumber10maximum size of the image in MB
maxFilesNumbernumber5maximum number of files to be uploaded at once
allowedMimeTypesstring[]nullall image types
imageMaxWidthnumber1920maximum width of the image
imageMaxHeightnumber1080maximum height of the image
maxMediaLegendLengthnumber100maximum character length of the image legend

New features

VersionsFeatures
v0.11.0
  • Can use both inline code and code blocks.
v0.10.0
  • Can position the toolbar at the top or bottom.
v0.09.33
  • Can show or hide Editor/Preview tabs.
v0.9.29
  • Compatible with Next.js (v13+). See example
v0.9.19
  • Copy the code block
v0.9.11
  • Upload image via drop, paste or upload button
  • Add or edit the image alt text and legend
  • Reorder toolbar menus

Contributing

Get started here.

Keywords

FAQs

Package last updated on 13 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc