Hello, I am new to your project, but I love it. I have a small issue with image attributes.
Question
I added two new traits to the trait manager for images. Width and height. I added it as a plugin following your example. It totally works and lets me edit the image attributes for width and height. The problem is that now the asset manager doesn't work any more. If I disable my changes then the asset manager works again. Is there any way that I can have both working? My new traits and the asset manager for images?
Here is my code for adding the new traits. To activate it I just call the function name as a plugin. Did I do something wrong maybe? Please help!!!!
function AddImageTraits(editor) {
var domComps = editor.DomComponents;
var dType = domComps.getType('default');
var dModel = dType.model;
var dView = dType.view;
domComps.addType('image', {
model: dModel.extend({
defaults: Object.assign({}, dModel.prototype.defaults, {
traits: [
// strings are automatically converted to text types
'name',
'id',
'alt',
'width',
'height'
]
}),
}, {
isComponent: function (el) {
if (el.tagName == 'IMG') {
return {
type: 'image'
};
}
},
}),
view: dView,
});
Answers (3)
Try to override from the image type itself instead of default type
As already mentioned by @arthuralmeidap you have to extend the image component.
So in your case (by using the latest grapesjs version) it could just be:
editor.DomComponents.addType('image', {
model: {
defaults: {
traits: [ 'name', 'id', 'alt', 'width', 'height']
}
}
});
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.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #612
Urgent : Duplicate other blocks when used custom asset manager
Hello, We have modified the Assset manager with custom one. But we are having problem now. If we drop one image into canvase and then add a...
Issue #1266
Could not load updates images in the assetmanager
We are saving the components to the MySQL database .So when we load the components we don't get updated value for example in asset manager...
Issue #1929
Loads asset manager, but assets not working
I'm using the pencil icon to trigger the asset manager. The triggering works fine but when I click on any of the images, no change is refle...
Issue #1661
I've created html table and cannot drag new elements to table cells
Hello. if I create html table with next block of code, everything works, I'm able to drop a Quote, for example, to any cell: But next code...
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.