GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.37k stars 4.05k forks source link

Insert block in canvas/domComponents. #235

Closed ErnestsMillers closed 7 years ago

ErnestsMillers commented 7 years ago

I am working with grapesjs-mjml and I have created a CKEditor plugin. The following event happens on CKEditor dialog OK button press.

All I need to do is take a predefined block and then use domComponents to add it inside wrapper in the editor. Could you help with this? I couldn't find a way in docs or I am just doing something wrong.

It shows up and sort of works if I restart the page. But on event I get this: Uncaught TypeError: e.join is not a function, and it gets placed inside 'Box' element, that can be seen in Layer Manager. It also breaks MJML parsing into HTML, the element just doesn't show up in output. And on View Code press I get Line 1 (div) — Element div doesn't exist or is not registered.

This is what I have now:

var blockManager    = editor.BlockManager;
var domComponents   = editor.DomComponents;
var wrapperChildren = domComponents.getComponents();

var mjText = blockManager.get('mj-text');

var comp1 = wrapperChildren.add(mjText.attributes);

Thank you in advance! :)

artf commented 7 years ago

You're adding attributes instead of the content

// From
var comp1 = wrapperChildren.add(mjText.attributes);
// To
var comp1 = wrapperChildren.add(mjText.content);
ErnestsMillers commented 7 years ago

Thank you a lot, @artf. The fix for me was actually: var comp1 = wrapperChildren.add(mjText.attributes.content);

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.