Giter Site home page Giter Site logo

anatoliy-t7 / tiptap-extension-image-resize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coolswitch/tiptap-extension-image-freely

1.0 0.0 0.0 2.66 MB

Image extension for tiptap, support resize or rotation

License: MIT License

TypeScript 22.81% Vue 77.19%

tiptap-extension-image-resize's Introduction

tiptap-extension-image-resize

Image extension for tiptap

Use this library without using @tiptap/extension-image

  • Support picture resize and rotation
  • Support to expand other functions

eg

Instalation

npm i tiptap-extension-image-resize

Usage

Add it as any extension in useEditor()

import Image from 'tiptap-extension-image-freely'

  extensions: {
    Image.configure({
      inline: false,
      onExtraCreated: (eleExtra: HTMLElement, imgRef: HTMLImageElement) => {
        eleExtra.innerHTML = 'something else'
      },
      onError: (eleExtra: HTMLElement) => {
        eleExtra.innerHTML = '<errorIcon />'
      }
    }),

Image Configuration

export interface ImageOptions {
	// same as @tiptap/extension-image
	inline: boolean;
	allowBase64?: boolean;
	HTMLAttributes?: Record<string, any>;
	// Is support resize, default true
	resize?: boolean;
	// Resize icon, the default is a small black square
	resizeIcon?: any;
	// Is support rotate, default true
	rotate?: boolean;
	// Rotate icon
	rotateIcon?: any;
	/**
	 * expand other functions
	 * @param {HTMLElement} eleExtra - HTMLDivElement
	 * @param {HTMLImageElement} imgRef - Reference of image
	 */
	onExtraCreated?: (eleExtra: HTMLElement, imgRef: HTMLImageElement) => void;
	/**
	 * Callback for image loading failure
	 * @param {HTMLElement} eleExtra - HTMLDivElement
	 */
	onError?: (eleExtra: HTMLElement) => void;
}

Commands

editor.commands.setImage({
	src: 'https://xxxx/xx.png',
	alt: 'alt',
	title: 'title',
	width: '400px',
	rotate: '-180',
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.