How to add a block in Canvas on a specific position Onclick (Without Drag&Drop) #3682
Replies: 2 comments 4 replies
-
|
Hello, i've made some searchs. First: check the pasteCommand https://github.com/artf/grapesjs/blob/dev/src/commands/view/PasteComponent.js#L7 Checking the image, this is the component selected, i doesn't check it so deep, so i don't know where in this is the element position. Second: When you start a new plugin, it came with this code: editor.addComponents(
`<div style="margin:100px; padding:25px;">
Content loaded from the plugin
</div>`,
{ at: 0 } // <- Here is the position of a new element
)) |
Beta Was this translation helpful? Give feedback.
-
|
I updated the editor.Blocks.add('my-block', {
label: '...',
content: '...',
onClick: (block) => {
editor.getWrapper().append(block.get('content'), { at: 0 })
}
})ps. This will be available in the next release. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi , devs
Block config appendOnClick:1 it allow the block to add Onclick and it works fine.
but it appends the block into the selected element .
My Question is that how to append a block on a specific position Onclick .
Actually i want to add the block always as the nextSibling of the selected element.
i want something like this to catch click event. is it possible?
Beta Was this translation helpful? Give feedback.
All reactions