Issue #2179✓ SolvedOpened Aug 2, 2019by afdallah3 reactions

Auto wrap every component drag into canvas with another component

Quick answerby afdallah2

@pouyamiralayi I managed to solve the problem by making component as an object. Like so. Anyway thanks for trying to help.

Read full answer below ↓

Question

I am trying to make sure every component drag into the canvas to be wrapped with a column component. To achieve that I use canvas event. First I disabled window event to prevent default html 5 drag and drop event to be fired. canvas:drop event Let's say that my column component is so simple, only a single div. canvas:dragdata event Above code return error, saying that dataTransfer not defined What I understand is we can customize what we drop to the canvas with result.content something like or What I don't understand is how to wrap the dragged component with element/component.

Answers (2)

👍 Most helpfulafdallahAug 2, 2019

@pouyamiralayi I managed to solve the problem by making component as an object. Like so. Anyway thanks for trying to help.

pouyamiralayiAug 2, 2019

Hello there! the event you are looking for is this editor.on('block:drag:stop', function (element) { element.replaceWith({ tagName:'div', style:{'border': '1px solid red'}, components: [element] }) }) Notice here I am using a red bordered div as my wrapper; in your case it is the column. cheers.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.