quill icon indicating copy to clipboard operation
quill copied to clipboard

Option to insert an image from a URL

Open jasongisstl opened this issue 10 years ago • 39 comments

The Image button on the toolbar allows you to insert an image from your local machine. It would be brilliant if this could be extended to also allow an image URL to be provided.

It is possible to drag & drop an image from the web, but this may not be obvious to all users. Also, in our particular case, we have custom drag & drop handling which prevents this from working in our applications.

Version: 1.0.0-rc2

P.S. Thank you for all your hard work on 1.0 - it really is fantastic.

jasongisstl avatar Aug 26 '16 12:08 jasongisstl

Any progress on this?

laosb avatar Jan 23 '17 12:01 laosb

Also interested in this :)

CoenWarmer avatar Jan 24 '17 08:01 CoenWarmer

[edit]Best Approach is something like the adding a matcher to the clipboard module, watching for copypasted urls and converting them to images (new Delta().insert({image: url}); works) like the code found here: https://github.com/quilljs/quill/issues/109 by @schneidmaster Couldnt get it to works for images still tho...learning...

[edit 2] this custom matcher converts urls to links and in case they link to image, converts the urls to inline images (put it in quill.on('text-change', function(delta, oldDelta, source) {)


var Delta = Quill.import('delta');

//convert img links to actual images
quill.clipboard.addMatcher(Node.TEXT_NODE, function(node, delta) {
    var regex = /https?:\/\/[^\s]+/g;
        if(typeof(node.data) !== 'string') return;
            var matches = node.data.match(regex);

            if(matches && matches.length > 0) {
                var ops = [];
                var str = node.data;

                matches.forEach(function(match) {
                     var split = str.split(match);
                     if(match.match(/\.(png|jpg|jpeg|gif)$/)!=null){
                         var beforeLink = split.shift();                     
                         ops.push({ insert: beforeLink });
                         ops.push({ insert:{image: match}, attributes: { link: match } 
                      });

                    str = split.join(match);                    
                    } else { //if link is not an image
                        var beforeLink = split.shift();
                        ops.push({ insert: beforeLink });                        
                        ops.push({ insert: match, attributes: { link: match } 
                    }); 
                        str = split.join(match);
                    }                                                     
    });
                ops.push({ insert: str });
                delta.ops = ops;
             }                   
    return delta;
});


~~Obviously the wrong approach > I tried to implement this in the form of a custom module, but my JS skills suck. Behaviour im looking for is to replace all urls containing images to 'inline' images (like the etherpad image plugin). I made (read: copypasta) an example that sorta works here: http://codepen.io/anon/pen/PpYjxG In the example, type a bit and Copy/Paste an image url in the editor field and it will appear as inline image. Only after that the ability to edit/type stops, which must be something obvious, but as I said..major noob...~~

dennisdebel avatar Feb 22 '17 14:02 dennisdebel

Would love to see this as well. As a side note, this was how images were handled in the early stages of QuillJS. Any reason why this was removed?

tannerjt avatar Apr 23 '17 21:04 tannerjt

I don't understand why there is base64 upload images and no support for third-party image upload. This is VERY important!

masza avatar May 11 '17 16:05 masza

Still no update :(

cuduy197 avatar May 17 '17 01:05 cuduy197

I got it working like this: https://stackoverflow.com/questions/43857373/quill-editor-vuejs2-image-upload-base64-image-to-url Not directly from clipboard tho

McSneaky avatar May 24 '17 23:05 McSneaky

I think here https://github.com/quilljs/quill/issues/863#issuecomment-240579430 it is written pretty well. All you need to do is to create custom handler

Matoo125 avatar Jul 03 '17 12:07 Matoo125

+6666

vhq2016 avatar Nov 24 '17 08:11 vhq2016

+1

oliveratgithub avatar Feb 12 '18 21:02 oliveratgithub

I too would like to make public my desire for such a feature.

tedtoy avatar Feb 13 '18 07:02 tedtoy

+1

rodolfosaraiva avatar Apr 19 '18 14:04 rodolfosaraiva

+1 how is this not a feature yet?

Vice93 avatar Jul 18 '18 23:07 Vice93

Could someone from the team maybe shed some light on this please? This feature is really, REALLY needed.

davek1979 avatar Sep 05 '18 08:09 davek1979

+1 my team would love this feature.

owensco avatar Sep 28 '18 17:09 owensco

For what it's worth... would be really really nice to have...

alexjustesen avatar Nov 02 '18 13:11 alexjustesen

Keeping the fire alive for this request 🔥

alexandercsmith avatar Feb 16 '19 21:02 alexandercsmith

I toss some bricks into that fire so it keeps burning longer

oliveratgithub avatar Feb 17 '19 02:02 oliveratgithub

We got it working by extracting the base64 encoded image, storing it on the hard drive and replacing the src="data..." code with src="/folder/file..." but quill doesn't display the picture when the HTML is loaded with dangerouslyPasteHTML the next time we open it, see https://github.com/quilljs/quill/issues/1449.

+1 would also like to see this feature built-in

repat avatar Feb 27 '19 20:02 repat

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

            [{ 'header': 1 }, { 'header': 2 }],               // custom button values
            [{ 'list': 'ordered' }, { 'list': 'bullet' }],
            [{ 'script': 'sub' }, { 'script': 'super' }],      // superscript/subscript
            [{ 'indent': '-1' }, { 'indent': '+1' }],          // outdent/indent
            [{ 'direction': 'rtl' }],                         // text direction

            [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
            [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

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

            ['clean'],                                         // remove formatting button
            ['image']
        ];

        var quill = new Quill('#editor', {
            theme: 'snow',
            modules: {
                toolbar: {
                    container: toolbarOptions,
                    handlers: {
                        image: imageHandler
                    }
                }
            },
        });

        function imageHandler() {
            var range = this.quill.getSelection();
            var value = prompt('What is the image URL');
            if(value){
                this.quill.insertEmbed(range.index, 'image', value, Quill.sources.USER);
            }
        }

Gib-git avatar Apr 15 '19 18:04 Gib-git