-
Got this from @artf a while ago as alternative to a custom imageset implementation: editor.Components.addType('image', {
view: {
onActive(ev) {
ev && ev.stopPropagation();
const { model } = this;
editor.runCommand('core:open-assets', {
target: model,
types: ['image'],
onSelect(asset) {
const srcset = asset.get('srcset');
srcset && model.addAttributes({ srcset })
}
});
}
}
}) The problem is that the "onSelect" handler is never called when selecting an image in the asset manager even there's an option for such a handler here: https://github.com/artf/grapesjs/blob/ae1950761e277ae1c913b3a6a117127ff3019851/src/commands/view/OpenAssets.js#L13 Does anybody know why? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Works on my side (latest version), are you able to create a reproducible demo? |
Beta Was this translation helpful? Give feedback.
-
Works on double click. On single click, the asset manager stays open but the image is added to the page without srcset attribute if asset manager is closed. This seems to be inconsistent. Is there a way to add the attribute on single click too? |
Beta Was this translation helpful? Give feedback.
-
Yeah sure, just use the onClick option |
Beta Was this translation helpful? Give feedback.
Yeah sure, just use the onClick option
https://github.com/artf/grapesjs/blob/ae1950761e277ae1c913b3a6a117127ff3019851/src/commands/view/OpenAssets.js#L11
and here you can see how it is used on image assets
https://github.com/artf/grapesjs/blob/ae1950761e277ae1c913b3a6a117127ff3019851/src/asset_manager/view/AssetImageView.js#L44-L55