Issue #2611Opened February 29, 2020by orionseye0 reactions

[HELP] Dragging external content to Canvas

Question

I am trying to add d&d functionality from a modal which lists a bunch of html files (html snippets) .. into the editor canvas. Each of them enclose the content with a <section>

I tried to use 'canvas:dragdata' to allow dropping into canvas

editor.on('canvas:dragdata', (dataTransfer, result) => {
          if(el.tagName == 'SECTION' && el.classList.contains('section')){
		result.content = { type: 'text/html'}
          }
		
});

As i understood, this is to extend the file types can be dropped, GrapesJS supports text + image, so above approach should work?

Meanwhile, and after playing around with editor.DomComponents.addType i am changing the scope of my issue ..see comment below

Answers (2)

orionseyeFebruary 29, 20200 reactions

I am clarifying what i want to achieve: I have some 100+ html snippets which i use on current 'handcrafted' builder and need to migrate them to GrapesJS. To my surprise,, this doesn't seem to be a straight forward job. Currently, with 2 Ajax functions i achieve what is needed. a) ajax + scan_dir to list all files inside a directory (image & html file) b) user clicks (or drags) the (preview) image into editable div and Ajax retrieves the corresponding html file, placing it where desired. Done!

How can GrapesJS solve this?

At least, i was expecting that text/html with standard html5 tags is supported to drag into editor canvas, from outside the editor.

EDIT: Raw html can be dragged into the editor from outside, this might be a workaround as i see, without having to deal with components & blocks for each need

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.