grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Text disappear after creating a new type

Open algodata44 opened this issue 8 years ago • 3 comments

Hello!

I am creating a new block that will open a modal during the creation (drag and drop https://github.com/artf/grapesjs/issues/174 really helped me and it works.

But it had a surprising side-effect: When I select and deselect a text component, the text disappear. Here is the code, I think I changed the defaultType property unintentionally:

var defaultType = editor.DomComponents.getType('default');
   	editor.DomComponents.addType('importType', {
   	 		model: defaultType.model.extend({
   	 				isComponent: function(el){
   	 					if(el.tagName == 'IMPORTTYPE'){
   	 						return {type: 'importType'};
   	 					}
   	 				},
   	 		}),
   	view: defaultType.view.extend({
   	     init() {
   	       this.listenTo(this.model, 'active', this.doStuff); // listen for active event
   	     },
   	     doStuff() {...}
   	  }),
   	});

algodata44 avatar Jun 29 '18 09:06 algodata44

Wrong position for isComponent, it should be passed in the second argument object

defaultType.model.extend({
	isComponent //<- wrong
}, {
	isComponent //<- correct
})

So it's like not declaring it, and as mentioned in Components

As you're putting a new Component type on top of the stack, not declaring isComponent() might probably break stuff, especially if you extend the default one.

artf avatar Jun 30 '18 13:06 artf

It works perfectly, thank you!

algodata44 avatar Jul 02 '18 08:07 algodata44

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.

lock[bot] avatar Sep 17 '19 11:09 lock[bot]