addType problem, custom types doesn't work when editor init
Question
Notice some probleme with addType functionality
If I create some custom type like this:
editor.DomComponents.addType('widget', {
model: dModel.extend({
defaults: _.extend({}, dModel.prototype.defaults, {
type: ComponentId,
tagName: 'div',
classes: ['widget'],
productId: 1
}),
initialize: function(o, opt) {
dModel.prototype.initialize.apply(this, arguments);
var toolbar = this.get('toolbar');
toolbar.unshift({
attributes: {
class: 'fa fa-gear'
},
command: 'widget-settings'
});
this.set('toolbar', toolbar);
}
}, {
isComponent: function(el) {
var result = '';
if (el.tagName === 'DIV' && el.className.indexOf('widget') !== -1) {
result = {
type: ComponentId
};
}
return result;
}
}),
view: dView
})
When we add component widget on page , it work good
But after save content to the server and reload page custom type doesn't apply
because Parser don't have this type^ use only default types, so in widget type don't call isComponent method
here: https://github.com/artf/grapesjs/blob/dev/src/parser/model/ParserHtml.js#L131
Do you know this bug?
Possible solution is add some middleware here to add custom types and components to instance before call init
https://github.com/artf/grapesjs/blob/dev/src/index.js#L52 *
Answers (0)
No answers yet.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2614
[QUESTION] Recursive view update of custom component
Hi, I have defined a custom type like: I want to keep the customTag in my model and show the content (HTML) in the view. However, in the co...
Issue #738
image reverted to original size after resized
hi, i got a strange issue with component: i got 2 types, image and icon the issue is when i first drag and drop the image component, i'm ab...
Issue #1148
Script in component get messed up, any idea?
I created a component like const TWITTERTYPE = 'TWITTER'; domc.addType(TWITTERTYPE, { model: defaultModel.extend({ defaults: { ...defaultMo...
Issue #2697
[QUESTION] Problem with custom component type and table cell
Hello! I'm trying to add custom component type: And also I'm adding new block: But when I drop this block on the canvas the <td> tag doesn'...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.