GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.36k stars 4.05k forks source link

[QUESTION] Call parent method from within plugin #2625

Closed DRoet closed 4 years ago

DRoet commented 4 years ago

Hi @artf,

What would be the recommended way of calling a grapesjs method from within a plugin? The grapesjs-mjml plugin uses this.MethodName() (https://github.com/artf/grapesjs-mjml/blob/7a9712ce7a401079f31932a7fe2c342657e85efa/src/components/index.js#L248)

However when the plugin gets minified in the production bundle, the plugin no longer works since there is no direct inheritance w/ grapesjs.

Is there a way to call the functions/variables from the Editor object directly? since this is the only variable that gets directly passed to the plugin. So for example this.methodName() would become editor.View.methodName() or something similar.

EDIT: example of downstream issues: https://github.com/artf/grapesjs-mjml/issues/155, https://github.com/artf/grapesjs-mjml/issues/166

artf commented 4 years ago

Probably you would need something like this

const View = editor.DomComponents.getType('default').view;
View.prototype.renderAttributes.apply(this);

in any case, seems really weird that the minifer makes such an unsafe removal. I use something similar here and it doesn't break