Skip to content

bae-sh/tiptap-extension-resize-image

Repository files navigation

tiptap-extension-resize-image

npm version npm downloads license GitHub stars

tiptap-extension-resize-image

Tiptap is a suite of open source content editing and real-time collaboration tools for developers building apps like Notion or Google Docs.

This package provides the ability to adjust the size of the tip tab image. It has been tested in React, Vue, and NextJS, and stability in VanillaJS may not be guaranteed. Additionally, it can align the image position.

Compatibility

tiptap-extension-resize-image Supported TipTap Versions
≤ 1.2.2 v2 only
≥ 1.2.3 v2 and v3

Installation

You can install it using npm:

$ npm install tiptap-extension-resize-image

Usage

import StarterKit from '@tiptap/starter-kit';
import ImageResize from 'tiptap-extension-resize-image';
import { EditorContent, useEditor } from '@tiptap/react';

const editor = useEditor({
  extensions: [StarterKit, ImageResize],
  content: `<img src="https://source.unsplash.com/8xznAGy4HcY/800x400" />`,
});

Use as inline

If you want to render images as inline elements, you can configure the extension like this:

const editor = useEditor({
  extensions: [
    StarterKit,
    ImageResize.configure({
      inline: true,
    }),
  ],
  content: `<img src="..."/>`,
});

Resize limits

You can set minimum and maximum width constraints to limit how small or large images can be resized:

const editor = useEditor({
  extensions: [
    StarterKit,
    ImageResize.configure({
      minWidth: 100, // Minimum width in pixels
      maxWidth: 800, // Maximum width in pixels
    }),
  ],
  content: `<img src="..."/>`,
});

Both minWidth and maxWidth are optional. You can set one, both, or neither:

// Only set a minimum width
ImageResize.configure({ minWidth: 50 });

// Only set a maximum width
ImageResize.configure({ maxWidth: 1200 });

// Set both constraints
ImageResize.configure({ minWidth: 100, maxWidth: 800 });

Options

Option Type Default Description
inline boolean false Render images as inline elements
minWidth number undefined Minimum width in pixels (cannot resize smaller)
maxWidth number undefined Maximum width in pixels (cannot resize larger)

Contributing

Contributions are welcome! Please read our Contributing Guide before submitting a Pull Request.

About

tiptap-extension-resize-image

Resources

License

Contributing

Stars

Watchers

Forks

Contributors