react-quill icon indicating copy to clipboard operation
react-quill copied to clipboard

The quill-image-resizing -module is not working properly, the image stays highlighted with resize options even clicking outside the editor

Open sarang-naico opened this issue 5 years ago • 21 comments

When I integrated the quill-image-resize-module with react-quill, the resizer stays in the screen even clicking outside the editor. The resizer getting closed when we click inside the editor. This is causing some bugs like, sometimes the resizing window is positioned outside of the image. Screenshot 2019-08-23 at 6 44 23 PM @chrismcv @jdhuntington @daggmano @Sajam @jacktrades Thanks!

sarang-naico avatar Aug 23 '19 13:08 sarang-naico

@sarang-naico Any news for this issue ?

M4gie avatar Dec 08 '19 10:12 M4gie

@M4gie I just edited the quill-image-resize library in-order to fix this issue

sarang-naico avatar Dec 11 '19 09:12 sarang-naico

I can share the code if you want @M4gie

sarang-naico avatar Dec 11 '19 09:12 sarang-naico

I found a solution here for my issue https://github.com/zenoamaro/react-quill/issues/224#issuecomment-311933020

M4gie avatar Dec 14 '19 14:12 M4gie

@sarang-naico : Could you please share the code ? Facing the same issue. @M4gie : Not sure how registering the module could solve this problem ?

ashishBharadwaj avatar Mar 11 '20 12:03 ashishBharadwaj

import React from 'react'
import ReactQuill, { Quill } from 'react-quill'
import 'react-quill/dist/quill.snow.css'
import ImageResize from 'quill-image-resize-module-react'
Quill.register('modules/imageResize', ImageResize)

function TextEditor(props) {

    const modules = {
        toolbar: [

            [{'header': [1, 2, 3, 4, 5, 6, false]}],

            ['bold', 'italic', 'underline', 'strike'],                                                      // toggled buttons
            ['blockquote', 'code-block'],

            [{'list': 'ordered'}, {'list': 'bullet'}, {'indent': '-1'}, {'indent': '+1'}, {'align': []}],
            [{'script': 'sub'}, {'script': 'super'}],                                                       // superscript/subscript
            [{'direction': 'rtl'}],                                                                         // text direction,

            [{'color': []}, {'background': []}],                                                            // dropdown with defaults from theme

            ['link', 'image'],

            ['clean']                                                                                       // remove formatting button
        ],
        imageResize: {
            // parchment: Quill.import('parchment'),
            modules: [ 'Resize', 'DisplaySize' ]
        }
    }

    return (
        <ReactQuill
            value={props.content}
            onChange={(value) => {
                props.setContent(value)
            }}
            modules={modules}
        />
    )
}

export default TextEditor; 

This is my Editor component, I didn't edit my webpack config.

M4gie avatar Mar 11 '20 12:03 M4gie

@M4gie Did it solve the actual problem ?

When I integrated the quill-image-resize-module with react-quill, the resizer stays in the screen even clicking outside the editor.

ashishBharadwaj avatar Mar 11 '20 14:03 ashishBharadwaj

Did you all solve the problem? I use Nextjs and can't find any solutions.

Kamez avatar Jul 04 '20 11:07 Kamez

Yes I did. But I had to make changes in the image resize module

You can refer to my repository : https://github.com/ashishBharadwaj/flawesome

Image-resize Component: https://github.com/ashishBharadwaj/flawesome/blob/master/src/components/imge-resize/ImageResize.js

I added a blur event listener like so:

this.quill.root.addEventListener('blur', this.handleFocusOut);

handleFocusOut = (evn) => {
        if(this.img){
            this.hideOverlay();
        }
}

I decided to include the code in my repo because apart from this I had several other use cases that I needed to handle like resized image state retention in case the editor is reinitialized with some content. And I was not able to build after forking the original repository

ashishBharadwaj avatar Jul 05 '20 04:07 ashishBharadwaj

@ashishBharadwaj It's not working with NextJS

Kamez avatar Jul 06 '20 15:07 Kamez

Hi, any update regarding the same? Stuck with a similar problem. Using NextJS.

nithinkashyapn avatar Aug 10 '20 17:08 nithinkashyapn

Same here, don't know how to implement it using Nextjs

nitink66 avatar Aug 23 '20 07:08 nitink66

@nitink66 @nithinkashyapn @Kamez

same Next.js problem.

use this next.config.js work for me:

module.exports = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.module.rules.push({
      test: /\.js$/,
      exclude: /node_modules(?!\/quill-image-drop-module|quill-image-resize-module)/,
      loader: 'babel-loader',
    })

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

    return config
  }
};

register:

import ReactQuill, { Quill } from "react-quill";
import ImageResize from 'quill-image-resize-module';
Quill.register('modules/ImageResize', ImageResize);

gladmo avatar Aug 24 '20 16:08 gladmo

Did anyone solve the problem in nextjs?

pk1997 avatar Sep 28 '20 08:09 pk1997

스크린샷 2020-12-11 오후 12 42 33

image doesnt resize is there any solution?


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

Quill.register("modules/ImageResize", ImageResize);

export const modules = {
   syntax: true,
   ImageResize: {
      handleStyles: {
         displaySize: true,
         backgroundColor: "black",
         border: "none",
         color: "white",
      },
      modules: ["Resize", "DisplaySize", "Toolbar"],
   },
   toolbar: [
      // [{ header: "1" }, { header: "2" }],
      [{ font: [] }],
      [{ size: ["small", false, "large", "huge"] }], // custom dropdown
      ["bold", "italic", "underline", "strike"],
      ["blockquote", "code-block"],
      [{ color: [] }, { background: [] }], // dropdown with defaults from theme
      [{ align: [] }],
      [{ list: "ordered" }, { list: "bullet" }, { indent: "-1" }, { indent: "+1" }],
      ["link", "image", "video"],
   ],

};`

- [ ] 

junggri avatar Dec 11 '20 03:12 junggri

Did anyone solve the problem in nextjs?

xiaoshengaimm avatar Feb 14 '23 09:02 xiaoshengaimm

I'm not aware of any resolution of this so far... looking at the files there is no "module/imageResize" class on quill folder.., maybe the author injected or somehow

ThalesMarzarotto avatar Mar 16 '23 05:03 ThalesMarzarotto

This might be a possible solution:

document.addEventListener('click', e => {
  const editorEl = document.querySelector(YOUR_EDITOR_ID/CLASS);
  if (!editorEl?.contains?.(e?.target)) { // click outside editor
    // do something such as cancel highlight        
  }
});

okjack365 avatar Apr 11 '23 12:04 okjack365

@M4gie I just edited the quill-image-resize library in-order to fix this issue

Can you provide me the code?

yeasin181015 avatar May 13 '23 16:05 yeasin181015

useEffect(() => { const quillEditorContext = textEditorRef.current; if (!quillEditorContext) return const quill = quillEditorContext.getEditor(); const imageResize = quill.getModule("imageResize") const quillRoot = quill.root const hideOverlay = async (event) => { if (!quillRoot.contains(event.target)) { imageResize.hide() } } document.getElementById("__next").addEventListener("click", hideOverlay) return () => { document.getElementById("__next").removeEventListener("click", hideOverlay) } }, [value])

pranav-sharma-au5 avatar Sep 07 '23 10:09 pranav-sharma-au5

Does anyone here know how to use this in next.js?

singleseeker avatar Oct 09 '23 06:10 singleseeker