Coder Social home page Coder Social logo

quill-image-resize-module's Introduction

Quill ImageResize Module

A module for Quill rich text editor to allow images to be resized.

Also see quill-image-drop-module, a module that enables copy-paste and drag/drop for Quill.

Demo

Plunker

Usage

Webpack/ES6

import Quill from 'quill';
import { ImageResize } from 'quill-image-resize-module';

Quill.register('modules/imageResize', ImageResize);

const quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        imageResize: {
            // See optional "config" below
        }
    }
});

Script Tag

Copy image-resize.min.js into your web root or include from node_modules

<script src="/node_modules/quill-image-resize-module/image-resize.min.js"></script>
var quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        ImageResize: {
            // See optional "config" below
        }
    }
});

Config

For the default experience, pass an empty object, like so:

var quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        ImageResize: {}
    }
});

Functionality is broken down into modules, which can be mixed and matched as you like. For example, the default is to include all modules:

const quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        ImageResize: {
            modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
        }
    }
});

Each module is described below.

Resize - Resize the image

Adds handles to the image's corners which can be dragged with the mouse to resize the image.

The look and feel can be controlled with options:

var quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        ImageResize: {
            // ...
            handleStyles: {
                backgroundColor: 'black',
                border: 'none',
                color: white
                // other camelCase styles for size display
            }
        }
    }
});

DisplaySize - Display pixel size

Shows the size of the image in pixels near the bottom right of the image.

The look and feel can be controlled with options:

var quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        ImageResize: {
            // ...
            displayStyles: {
                backgroundColor: 'black',
                border: 'none',
                color: white
                // other camelCase styles for size display
            }
        }
    }
});

Toolbar - Image alignment tools

Displays a toolbar below the image, where the user can select an alignment for the image.

The look and feel can be controlled with options:

var quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        ImageResize: {
            // ...
            toolbarStyles: {
                backgroundColor: 'black',
                border: 'none',
                color: white
                // other camelCase styles for size display
            },
            toolbarButtonStyles: {
                // ...
            },
            toolbarButtonSvgStyles: {
                // ...
            },
        }
    }
});

BaseModule - Include your own custom module

You can write your own module by extending the BaseModule class, and then including it in the module setup.

For example,

import { Resize, BaseModule } from 'quill-image-resize-module';

class MyModule extends BaseModule {
    // See src/modules/BaseModule.js for documentation on the various lifecycle callbacks
}

var quill = new Quill(editor, {
    // ...
    modules: {
        // ...
        ImageResize: {
            modules: [ MyModule, Resize ],
            // ...
        }
    }
});

quill-image-resize-module's People

Contributors

gbenson-wikia avatar kensnyder avatar lozjackson avatar nmonterroso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quill-image-resize-module's Issues

Documentation error

image
In the Readme.md, many examples are using ImageResize, instead of imageResize, except the first one. The former will result in JavaScript error. This small documentation error should be corrected, in order not to mislead first time comer.

Thanks for this great plugin for Quill.

Disable ImageResize Module

Hello. Is it possible to disable image-resize modue for readonly state of the quill editor?
I was trying to remove the listener from the quill.root, but it didn't help.
What the status about this functionality?

Trigger 'editor-change' when user changes image alignment

Description

I scratched my head for hours to verify this before even posting.
I founded out that when a user interacts with the alignment Toolbar, there is no 'editor-change' event being triggered.
I can be a problem when a user change alignment as final action since it will not be registered by my Vue component (I rely on a change event bound to Quill editor-change event).

Demo

  1. open this plunkr
  2. open dev console
  3. try resizing an image: editor-change triggered
  4. try changing alignment: no editor-change 😭

vue CLI 3 import image resize module

I use vue cli 3 and last version this repo .

import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

import Quill from 'quill';
import { quillEditor } from 'vue-quill-editor';
// image drop
import { ImageDrop } from 'quill-image-drop-module';
Quill.register('modules/imageDrop', ImageDrop);

console log

image-resize.min.js?f318:1 Uncaught TypeError: Cannot read property 'imports' of undefined
    at Object.eval (image-resize.min.js?f318:1)
    at e (image-resize.min.js?f318:1)
    at Object.eval (image-resize.min.js?f318:1)
    at e (image-resize.min.js?f318:1)
    at eval (image-resize.min.js?f318:1)
    at eval (image-resize.min.js?f318:1)
    at eval (image-resize.min.js?f318:1)
    at eval (image-resize.min.js?f318:1)
    at Object../node_modules/quill-image-resize-module/image-resize.min.js (app.js:2556)
    at __webpack_require__ (app.js:725)

why do not you change the documentation if it will not work like the documentation? !!

example
https://codesandbox.io/s/18vz06x1j7

Module cannot find in type script

I am using Type script. It shows ImageResize module is not defined when I Import the module.
Note that I have already installed ngx-quill.

Misconfigured babel plugins - Cannot compile the library out of the box

babel-loader settings in webpack.config.js need to be fixed.
ESNext feature proposal-class-fields won't be handled printing the message below

ERROR in ./src/ImageResize.js
Module parse failed: /Users/carl/workspace/theta_cursor/node_modules/quill-image-resize-module/src/ImageResize.js Unexpected token (50:22)
You may need an appropriate loader to handle this file type.
|     }
| 
|     initializeModules = () => {
|         this.removeModules();
|

You have to edit babel-loader plugins as shown below

                        "plugins": ["transform-class-properties"]

Image align styles not being retained when they are already set

I cannot get the image styles that are set with the align to be kept when re-displaying the image inside a quill editor.

Use case:

  1. Add and right align an image in the editor.
  2. Save the editor innerHTML in a database
  3. Redisplay the edited HTML in a new quill editor to allow user to update the HTML

Expected: image in the new editor should still be aligned right.
Actual: image in new editor has had all the style attributes removed

I've updated the demo Plunk to show the issue. In this example, I've added the align style attributes to the first image in the HTML (style="display: inline; float: right; margin: 0px 0px 1em 1em;"). The editor has removed them and the image is not being aligned right.

NPM release stale

Hi Ken,

Thanks for the awesome Quill plugin! I'm making good use of it on a personal project.

I'm still getting this message in the console when using your plugin, though I see a commit on this repo that removes said message: b82c02b

screen shot 2017-09-25 at 9 41 31 am

I'm assuming NPM hasn't been updated with the latest build. If so, could I kindly ask you to update it?

Thank you!

Double click on image

After a add resize image module into quill. I couldn't do event double click on the image

Using Quill and React `TypeError: window.Quill is undefined` error

I made a sample application (https://github.com/pc-magas/react-quill-demo) using react and Quill expecially the https://github.com/zenoamaro/react-quill and I am trying to load the plugin. But I get the error:

TypeError: window.Quill is undefined

Do you fellows have an Idea why does it happen?

The project I did it to have a clear base to demonstrate the possibe bug.The file that throws it is: https://github.com/pc-magas/react-quill-demo/blob/master/src/MyEditor.js

The libraries that I use are:

Also I used the normal Quill library had had the very same error.

Link of image does not show tooltip on click

Hello everyone.
I have the issue. When I use quill-image-resize-module, and want to add link on the image it is created as the a tag. But when I focus on the image, the element with class .ql-tooltip is not shown for me.

'imports' of undefined

Using Vue.js 2.2.6 with official webpack template and Vue-Quill-Editor

Console logs in dev run:

Uncaught TypeError: Cannot read property 'imports' of undefined (image-resize.min.js?c9ce:1)

Code here:

// main.js
<script>

    import Vue from 'vue';
    // some plugins here
    import VueQuillEditor from 'vue-quill-editor';
    Vue.use(VueQuillEditor);
    
</script>

// some *.vue file
<script>

	import Quill from 'quill';
	import { ImageResize } from 'quill-image-resize-module';

	Quill.register('modules/imageResize', ImageResize);

	export default {
		name: 'editor',
		data() {
			return {
			    // some code
				Editor: {
				    // some code
					options: {
					    // some code
						modules: {
							imageResize: {
								displaySize: true
							}
						}
					}
				}
			}
		}
	}
</script>

Introduce version

There has been no stable tag for this project. Some nice things have been added since its initial release and some small fixes (removing console.log calls etc.). I think it deserves a stable release.

with Angular4, TypeError: Cannot read property 'imports' of undefined

i tried to add the ImageResize module to the ng2-quill-editor component,

import * as Quill from 'quill';
import ImageResize from 'quill-image-resize-module';

Quill.register('modules/imageResize', ImageResize);

and added

  ImageResize: {
      modules: ['Resize', 'DisplaySize', 'Toolbar']
    }

to the options inside the component, but am getting

image-resize.min.js:1 Uncaught TypeError: Cannot read property 'imports' of undefined
at Object. (image-resize.min.js:1)

any idea how to solve this error ?

Compiler error on typescript

I am trying to use this quill-image-resize-module for ngx-quill.I have installed ngx-quill and it is working fine. Now I need to resize the image inside the editor, so I am trying to use it.
The problem is it is written in JavaScript and I am trying to use it in typescript file(Inside a component), So I got a compiler error.

As the documentation have said that I have to import and register the ImageResize module But I am getting a compiler error while importing.

Can Anyone help me on using that module.

Append control divs to Quill's parent element instead of document body?

Thanks for putting this module together--we were badly in need of a way to resize images in Quill and this really helped us out!

We have a single-page application with a Quill editor inside a scrollable container. Since the control boxes of the image resize module are appended to document.body, I found that scrolling the container would cause the resize boxes to drift away from their image:

screen shot 2017-04-06 at 11 32 41 am

To fix this, instead of appending the control divs to document.body, I append them to quill.root.parentElement. And instead of calculating their position using this.img.getBoundingClientRect(), I use this.img.offsetLeft and this.img.offsetTop to get positions relative to the container.

I'm not sure how generalizable this is, though. Would there be any drawbacks to always appending the control divs to quill.root.parentElement?

In any case, thanks a lot for your work on this module.

npm/fsevents install problem

I am having trouble installing ImageResize npm module (in osx 10.12.5):

$ npm i quill-image-resize-module
npm WARN deprecated [email protected]: Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm WARN deprecated [email protected]: catastrophic backtracking in regexes could potentially lead to REDOS attack, upgrade to 2.17.2 as soon as possible

[email protected] install /Users/taskaijo/web/project1/node_modules/quill-image-resize-module/node_modules/fsevents
node install

node-pre-gyp info it worked if it ends with ok
node-pre-gyp verb cli [ '/usr/local/Cellar/node/8.1.1/bin/node',
node-pre-gyp verb cli '/Users/taskaijo/web/project1/node_modules/quill-image-resize-module/node_modules/fsevents/node_modules/.bin/node-pre-gyp',
node-pre-gyp verb cli 'install',
node-pre-gyp verb cli '--fallback-to-build' ]
node-pre-gyp info using [email protected]
node-pre-gyp info using [email protected] | darwin | x64
node-pre-gyp verb command install []
node-pre-gyp info check checked for "/Users/taskaijo/web/project1/node_modules/quill-image-resize-module/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" (not found)
node-pre-gyp http GET https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.1.1/fse-v1.1.1-node-v57-darwin-x64.tar.gz
node-pre-gyp http 404 https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.1.1/fse-v1.1.1-node-v57-darwin-x64.tar.gz
node-pre-gyp ERR! Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.1.1/fse-v1.1.1-node-v57-darwin-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v57 ABI) (falling back to source compile with node-gyp)
node-pre-gyp http 404 status code downloading tarball https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.1.1/fse-v1.1.1-node-v57-darwin-x64.tar.gz

node-pre-gyp verb command build [ 'rebuild' ]
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

ImageResize is undefined after import

I am having trouble registering ImageResize in my Vue component becuase, for some reason, it is undefined. I'm kind of confused, because the same procedures work fine for ImageDrop

yarn add quill-image-resize-module

Which added the following to my package.json

"quill-image-resize-module": "^3.0.0",

In my single file component:

  import Vue from 'vue'
  import Quill from 'quill'
  import VueQuillEditor from 'vue-quill-editor'

  import { ImageDrop } from 'quill-image-drop-module';
  import { ImageResize } from 'quill-image-resize-module';

  Quill.register('modules/imageDrop', ImageDrop)
  Quill.register('modules/imageResize', ImageResize) //ImageResize is undefined 

Any thoughts as to what I am doing wrong?

resize method is triggered too often and may cause some performance issues

when resize the img, the handleDrag method is triggered too often and may cause some performance problems
Could you set the img's size when the mouse up? or add a throttle function?

handleMousedown = evt => {
	...
		this.throttleDrag = this.throttle(this.handleDrag, 100);
		document.addEventListener('mousemove', this.throttleDrag, false);
		document.addEventListener('mouseup', this.handleMouseup, false);
	};
	handleMouseup = () => {
       ...
		document.removeEventListener('mousemove', this.throttleDrag);
		document.removeEventListener('mouseup', this.handleMouseup);
	};

throttle = (fun,delay)=>{
    var timer = null;
    var startTime = Date.now();  
    return function(){
        var curTime = Date.now();
        var remaining = delay-(curTime-startTime); 
        var context = this;
        var args = arguments;
        clearTimeout(timer);
        if(remaining<=0){ 
            func.apply(context,args);
            startTime = Date.now(); 
        }else {
		timer = setTimeout(() => {
			fun.apply(context, args);
		}, remaining);
	}
    }
}

Cannot resize image again

I have an image and can resize it once after it's first uploaded, but I am unable to resize the image again after this. I am currently using V 1.0.0 because I wasn't able to run on V3.0.0, I am also using ReactQuill.

UPDATE:

The error that is logged out is:
screen shot 2017-06-22 at 1 27 36 pm

eslint error

Hi,

I try to use quill-image-resize-module with react-quill in a react component but the build fails.

I have an error with eslint module but I don't know what is wrong.
The error is:

quill-image-resize-module/node_modules/eslint/lib/api.js didn't return a function

Is it a problem with eslint version in quill-image-resize-module?

Here is my code :

import React from 'react'
import ReactDom from 'react-dom'
import ReactQuill from 'react-quill'
import { ImageResize } from 'quill-image-resize-module'

export default class Test extends React.Component {
  constructor(props) {
    super(props)
    this.state = { text: '' }
  }

  componentWillMount() {
    ReactQuill.Quill.register('modules/imageResize', ImageResize)
  }

  handleChange(value) {
    this.setState({ text: value })
  }

  render() {
    var modules= {
      ImageResize: {
        modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
      },
      toolbar: [
        // [{SizeStyle : SizeStyle}],
        [{ 'size': ['small', false, 'large', 'huge'] }],
        [{ 'header': [1, 2, false] }],
        ['bold', 'italic', 'underline','strike', 'blockquote'],
        [{'list': 'ordered'}, {'list': 'bullet'}, {'indent': '-1'}, {'indent': '+1'}],
        ['link', 'image'],
        ['clean']
      ]
    }

    var formats= [
      'header',
      'bold', 'italic', 'underline', 'strike', 'blockquote',
      'list', 'bullet', 'indent',
      'link', 'image'
    ]

    return (
      <div className="text-editor">
        <ReactQuill theme="snow"
                    modules={modules}
                    formats={formats}>
        </ReactQuill>
      </div>
    )
  }
}

Register Image Resize using Angular 4

Hello
I'm trying to use image resize plugin inside angular 4 app.

i noticed that i should use a webpack and configure the webpack .config.js file in order to get rid of

Cannot read property 'imports' of undefined

so, i used the anulgar cli before i eject the webpack.config.js file using the following command:
ng eject

this produced the webpack.config.js file, i tried to modify it by inserting the following code "Base on the following issue and comments": #7 (comment)

i successfully added this

{
    test: /\.js$/,
    exclude: /node_modules(?!\/quill-image-drop-module|quill-image-resize-module)/,
    loader: 'babel-loader',
    query: {...}
  } 

to the modules in webpack.config.js file.

and the i added this to the plugins:

 new webpack.ProvidePlugin({
    'window.Quill': 'quill'
  })

but whenever i tried to build the app using

npm run build

it fails.

do you have any suggestions?

cannot import ImageResize from 'quill-image-resize-module';

hello,I am using anular4, when I put the mouse over it, the prompt
Could not find the declaration file "C:./Users/Ying/Desktop/work/node_modules/[email protected]@quill-image-resize-module/ image" of the module "Sleeve Image Resizing Module" -resize.min.js "implicitly possesses" any "type." If it does, trynpm install @ types / quill-image-resize-moduleor add a new declaration (.d.ts) file containingdeclare module'quill-image-resize-module';[7016]

Casing is wrong in example

When using Quill on a html page without webpack or anything, the example says to do the following to load the module.

ImageResize: {
// See optional "config" below
}

This doesn't work and throws an error saying it can't find a module by that name. Changing ImageResize to imageResize makes it work though.

Internet Explorer specific bug with image resizing

When testing my own application with your amazing module, I did come across an unexpected bug. When in Internet Explorer, click on a resizeable image. You will notice the following:

  1. There is no alignment toolbar (left, right and center aligned buttons)
  2. You can resize horizontally and vertically
  3. It resets the image to a smaller size, so you can't ever resize larger than a certain height.

I used your plunker to verify it: https://plnkr.co/edit/gq708AOrSBOWSlHcFslG?p=preview

Here is a GIF describing these things:
video-resizing-ie-bug

Thank you @kensnyder for building this module, it is a great help to us!

Minor - extra console output

Heads up that you left some logging in the latest build.

this.options.modules (3) ["DisplaySize", "Toolbar", "Resize"] prints for every quill created that includes the module.

Image attributes disappear when a htmlString value or delta is loaded into ReactQuill

I am having this issue and cannot figure out how to solve it.
I can resize and align images in the editor. However, when I reinsert the string value or delta into Quill, image size go back to its original size. Alignments of images also get lost.

Can anyone tell me how to properly insert the data back to react quill so that the image attributes do not disappear?

Angular 6 - only attribute is width

After registering the module with default settings and importing an image into the editor, and changing the images size and alignments, the only attribute available on the Delta is width.

Quill.register('modules/imageResize', ImageResize);

    this._quill = new Quill('#editor', {
      modules: {
        toolbar: this.quillOptions,
        imageResize: true
      },
      theme: 'snow'
    });

Delta:

{
	"ops": [{
			"insert": "some test text that is being typed"
		},
		{
			"attributes": {
				"width": "372"
			},
			"insert": {
				"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyU.............."
			}
		},
		{
			"insert": "\n"
		}
	]
}

I am assuming that this module should return a delta with additional attributes on the image op after the image has been aligned to center for example.

Regards,

schmorrison

Cannot read property 'imports' of undefined Nuxtjs/SSR

Getting the following error when i am adding the module to Quill.

Uncaught TypeError: Cannot read property 'imports' of undefined
    at Object.<anonymous> (app.508b1bdd306748193b03.js:9923)
    at e (app.508b1bdd306748193b03.js:9923)
    at Object.<anonymous> (app.508b1bdd306748193b03.js:9923)
    at e (app.508b1bdd306748193b03.js:9923)
    at app.508b1bdd306748193b03.js:9923
    at app.508b1bdd306748193b03.js:9923
    at webpackJsonp../node_modules/quill-image-resize-module/image-resize.min.js (app.508b1bdd306748193b03.js:9923)
    at Object../node_modules/quill-image-resize-module/image-resize.min.js (app.508b1bdd306748193b03.js:9923)
    at __webpack_require__ (manifest.2ea815068b6b951c57aa.js:713)
    at fn (manifest.2ea815068b6b951c57aa.js:118)
~/plugins/nuxt-quill-plugin.js

import Vue from 'vue'
import Quill from 'quill'
import { ImageResize } from 'quill-image-resize-module'

if (process.browser) {
  const VueQuillEditor = require('vue-quill-editor/ssr')
  Quill.register('modules/imageResize', ImageResize)
  Vue.use(VueQuillEditor)
}

Added Image Rotate

Not an issue but more of a tip!

I added Image rotate to this library and it was pretty simple.
Changes:-

  • Added buttons to the current align tool bar
  • Added name so I can track when rotate buttons are clicked (They can be clicked repeatedly)
  • Added basic function to check where the image was in the rotation cycle.
  • Used the quill Undo and Redo buttons as my buttons.

It only requires the Toolbar.js file to be modified. (File here)
Toolbar.txt

I didn't want to add the code as there might be a better implementation? But I thought this might help someone?

image

setContents did not work?

After resizing an image, quill.getContents() does add attributes to the ops
But quill.setContents() did not seem to apply the attributes to the image
Can anyone help me try?

Image stays 'selected' after editor loses focus

The image still says selected after the editor loses focus. The selecting logic probably needs to be better integrated with the Quill selection API. I will make a pull request to try to resolve this and possibly #11 at the same time.

License

Can a license be added so we can include this library in our projects?

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.