First of all, I really appreciate your replies on my questions. Thank you for all.
Question 1 : I've a situation where if a particular block is already in the canvas, I can't let that block to be added again. What I'm doing is, I'm listing to block:drag:start and compares if the component is already dropped (in gjs-components), I got success till now, but how to prevent the drag event right there?
Question 2 : When a component is bound to specific tag/component, where can listen when the invalid drop happens?
Question 1 : I've a situation where if a particular block is already in the canvas, I can't let that block to be added again. What I'm doing is, I'm listing to block:drag:start and compares if the component is already dropped (in gjs-components), I got success till now, but how to prevent the drag event right there?
I'd suggest to move this logic to components. So create a new component type (eg. my-cmp) and setup few listeners:
editor.on('component:add', component => {
if (component.is('my-cmp')) {
editor.BlockManager.get('my-cmp-block') // eg. hide the block
// ...
}
});
editor.on('component:remove', component => {
if (component.is('my-cmp')) {
editor.BlockManager.get('my-cmp-block') // eg. show the block
// ...
}
});
Question 2 : When a component is bound to specific tag/component, where can listen when the invalid drop happens?
Currently you can do it only via sorter:drag:end event
editor.on('sorter:drag:end', (targetCollection, modelToDrop, errors) => {
if (errors.length) {
console.log('errors', errors);
}
})
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.
Most helpful comment
I'd suggest to move this logic to components. So create a new component type (eg.
my-cmp) and setup few listeners:Currently you can do it only via
sorter:drag:endevent