-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow plugins to be defined as functions #1301
Conversation
Thanks for the feedback, I'll see about adding some tests and docs soon. |
FYI - I might have gone too far with the docs. I think that this new functional approach to plugins is much nicer that the old namespace approach, and I'd like to see all plugins migrated this way. That is in part because in our project we have problems with this: export default grapesjs.plugins.add('my-plugin-name', (editor, options) => {
console.log(options);
//{ customField: 'customValue' }
}) Because we use a bundler and lots of tests, it's a pain to always force import grapesjs from 'grapesjs'
windows.grapesjs = grapesjs
function onLoad(){
require("grapesjs-preset-newsletter");
} That sounds like a bigger project, but I figured it would be a good idea to share. |
@artf Can you have a look at this CI error? Tests are working locally.
^ that's the error that I'm getting, and it sounds unrelated to the feature I added |
Thanks Logan, about your issue with other plugins I think that happens because of the previous boilerplate when I wasn't using the BTW, I'm gonna merge this PR because I like the approach and it doesn't cost too much, but still not sure about using it as a recommended way, especially when you use plugins directly in the browser <script src="/your/path/to/grapesjs.min.js"></script>
<script src="/your/path/to/grapesjs-plugin.js"></script>
...
grapesjs.init({
container : '#gjs',
plugins: [ ?? ] // would require some kind of global
})
Seems to be related here, I think with a new version of jest will be fixed |
To be clear, your plugin already provides a global export UMD module by default. Current state
Plugins can use either Proposed stateIf you embraced plugins as functions, you would remove 1 of your 3 namespaces.
Ideally your plugins and boilerplate would use a more sane UMD export.
|
Thanks for the suggestion, Logan. Just to be clear, with the proposed state UMD namespace implies the plugin developer to define explicitly the global, eg. const myPlugin = editor => { ... };
window.myPlugin = myPlugin;
export default myPlugin; correct? |
Not quite correct. Webpack will turn There should be no need to ever manually add library to
So That seems reasonable to me. |
I'd say more like this In that case, for the next release, I'll add the check inside the |
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. |
As a developer that is using a lot of custom GrapesJS plugins, I would like to import plugins and use them directly without having to define them in the global plugin registry.
This allows my code to be more modular without having to worry about another plugin using the same string namespace that my plugin is trying to use.
Benefits:
Using imports
Using local plugins
Lambda plugins