grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Add new Components to editor

Open piyalmaduranga opened this issue 9 years ago • 18 comments

i need to Add new components to editor like Image drag and drop , mynew components contain script like this

(this script show image)

screenshot from 2017-01-26 11 34 59 how to add button to open box toolbar ? how to add setting that component ?

i tried to this way

var domComponents = editor.DomComponents; ....... domComponents: { components: '', } .....

how can i add modal pop up after drop component to our template ? (like image drop component)

piyalmaduranga avatar Jan 26 '17 09:01 piyalmaduranga

Hi @piyalmaduranga those in the image are what I call Blocks, and a Block contains Components.

var blockManager = editor.BlockManager;

// Add new block
blockManager.add('my-block-id', {
  label: 'Simple block',
  content: '<div class="my-block">This string will be parsed and turned into a Component</div>',
});

// Edit
blockManager.get('my-block-id').set({
  label: 'Updated simple block',
  attributes: {title: 'My title'}
});

// Add a block as a Component
blockManager.add('my-map-block', {
  label: 'Simple map block',
  attributes: {
    class:'fa fa-map-o'
  },
  content: {
    // Built-in 'map' component
    type: 'map',
    style: { height: '350px'},
    // Once inserted it can't be removed (just an example)
    removable: false
  }
});

how can I add modal pop up after drop component to our template?

If you want to add custom behavior to your Components (eg. pop up a modal when inserted into the canvas, do something when is double clicked, etc.) you need to define a new Component type but I've not yet added those API to GrapesJS but are coming soon.

artf avatar Jan 26 '17 12:01 artf

Hi @artf

I tried load the script inside editor,

 blockManager.add('advert-id', {
        label: 'advert',
        content: '<div id="advertDiv"><script src ="https://www.sample.net/invocationcode"></div>',
    });

When I add component into template.It is not generate script tag.I want to get work script that I inserted.

block content is : <div id="advertDiv"><script src ="https://www.sample.net/invocationcode"></div>

It included script tag. but result not show script tag statement. Only show <div id ="advertDiv"></div> missing my external script

Can I add external javascript block into template?

piyalmaduranga avatar Jan 27 '17 09:01 piyalmaduranga

@piyalmaduranga I'm still in progress to make templates work properly with javascript so for this reason I simply throw away all script tags, I can eventually add a new config property to let it import but not sure about the consequence

artf avatar Jan 27 '17 12:01 artf

HI @artf i added block using block manager it was like then i save my edited template and i tried edit this template again , in this time run script that i added it show image with tag and

Owner


Other Repo Issues