GrapesJS / style-bg

Full-stack background style property type for GrapesJS, with the possibility to add images, colors, and gradients
MIT License
33 stars 18 forks source link

Problem with asset manager #7

Closed hitaloramon closed 1 year ago

hitaloramon commented 3 years ago

Hi @artf,

I have a custom asset manager in my project that works normally when I add an image and use it to select an item. However in the style-bg plugin when I click the button to open select an image for the background my file manager opens and when I select the image nothing happens. Is there anything that needs to be done to work in the style-bg plugin?

Obs: I'm using the latest versions of grapejs and the style-bg plugin

editor.Commands.add('open-assets', { run(editor, sender, opts = {}) {... var image = 'path-img.jpg'; opts.target.set('src', image ); } })

sizhousama commented 3 years ago

hi @hitaloramon , I have the same problem, is your problem solved ?

hitaloramon commented 3 years ago

Hi @sizhousama,

I managed to resolve it. I put the complete example, but what suits you is from line 9 to 25

https://pastebin.com/f12dMm9p

mstevens625 commented 2 years ago

@hitaloramon, I have the same issue but your link doesn't appear to work. Would you mind sharing your solution?

hitaloramon commented 2 years ago

@mstevens625 link working

mstevens625 commented 2 years ago

Thanks @hitaloramon, that helped tremendously.

chaegumi commented 1 year ago

I use it with ckfinder,this is my code,it do not work.


    cmdm.add('open-assets', {
        run(editor, sender, opts) {
            // console.log(editor)
            // console.log(editor)
            console.log(editor);
            console.log(sender);
            console.log(opts)

            var finder = new CKFinder();
            finder.basePath = '/resource/ckfinder/';
            finder.selectActionFunction = function(fileUrl, data) {
                console.log(opts)
                opts.target.set('src', fileUrl);

                console.log(opts.target)
            }
            finder.selectActionData = '';

            finder.popup();
        }
    });

image

chaegumi commented 1 year ago

This work


        assetManager: {
            custom: {
                open(props) {
                    var finder = new CKFinder();

                    finder.basePath = '/resource/ckfinder/';
                    finder.selectActionFunction = function(fileUrl, data) {
                        // opts.target.set('src', fileUrl);
                        props.select(fileUrl);

                        props.close();
                    }
                    finder.selectActionData = '';

                    var api = finder.popup();
                },
                close(props) {
                    // finder.close();
                }
            }
        },