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
[FEATURE] Adding custom GrapeJS plugins to customize the editor #12429
Conversation
59df9ad
to
d9620dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea and would like to see it implemented in M5.
But I fetch it, run composer install, install the plugin, and enable it.
But I see no logs in the browser console.
Can you help me with make proper tests?
@kuzmany |
@Moongazer ah, understand. I think it was built during the composer install, like others npm packages. |
I think there was another reason why I didn't add the compiled builder.js: I just tried again to compile it via
So I think the M5 repo from where I branched off for this PR was broken already. The node package Edit: |
d9620dd
to
a7bf405
Compare
It would be so cool to have this functionality. I have some customers who require the development of special GrapesJS blocks to provide integration with e-commerce catalogs/products and allow them to easily compose emails with the products... The problem is I found there is no documentation supporting this kind of extensibility and seeing this pull request means there was not. I really hope it gets merged because I don't feel comfortable by modifying the core files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works. I vote to merge it to M5 Beta
@LordRembo probably related to investigation you're doing :) |
@escopecz consider it to merge M5 beta. It break nothing and bring way to extend builder |
@kuzmany I'll check, indeed an nice addition! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this!
- How come it's removing so much lines from package-lock.json?
- Could you copy the documentation from this PR description to https://github.com/mautic/developer-documentation-new?
@escopecz Regarding to 1): Not sure, but maybe it has to do with the rebasing? At the time I branched off, the NPM stuff was broken (that's why I couldn't compile the builder.js in the first place). Two weeks ago I rebased to the current 5.x branch and than it was working, so I guess other PRs have modified and fixed the package.json. For 2): I will see what I can do. |
Hi folks, if we can resolve the conflicts and get the docs together, we should be able to get this moving again. |
a7bf405
to
d37dec8
Compare
@RCheesley @escopecz I rebased to the current 5.x branch, so all conflicts should be resolved (not sure why the message above still showing "This branch has conflicts that must be resolved"). Unfortunately I don't have time to copy the description to docs (precisely: don't have time to setup the repo, figure out how to init and add everything, especially messing around with Python 3 installation on my Linux etc...). I'd appreciate if someone else could do this who has set up the docs repo already, thx 🙏🏼 |
@Moongazer Depends on what files are giving the conflicts. I had a similar problem and I saw the conflicts locally only when checking out the repo again in a new folder and pulled in all the 5.x changes, then did a git merge of 5.x on top of my branch. You'll probably have to do a similar thing. |
d37dec8
to
54943f4
Compare
@LordRembo OK I've rebased to current 5.x and built the assets again, please merge ASAP!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK to upgrade all dependencies in this PR? It would be easier to merge if the dependencies would be upgraded in a separate PR. But if the GrapesJS team decides this is OK then I'm also fine with it.
plugins/GrapesJsBuilderBundle/Assets/library/js/builder.service.js
Outdated
Show resolved
Hide resolved
I've written the docs here so it doesn't block merging if this can be tested in time for the release: mautic/developer-documentation-new#187 - please review it as I've just written what was here plus grammar fixes to align with the styleguide. Thanks! |
@escopecz The dependency updates are all minor updates (and of non-grapesjs dependent) node modules, so it should be okay. Maybe we should lock the versions in package json to only bugfix updates in future, I'll post the question in Slack and see what everyone thinks. |
@escopecz @LordRembo I had to delete the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion implementation! Re-approving 👍
…plugins provided by other Mautic plugin-bundles
…Plugins in initGrapesJS() function
2ca301e
to
5b2e2c9
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 5.x #12429 +/- ##
============================================
- Coverage 61.39% 61.39% -0.01%
Complexity 34024 34024
============================================
Files 2238 2238
Lines 101686 101686
============================================
- Hits 62431 62430 -1
- Misses 39255 39256 +1 |
@LordRembo from your comment I don't understand whether you approve or want some changes. Can you make it clear? |
@escopecz The comment was just to remark that the updates to the lock file should not be a blocker for the ticket. Haven't had time to do any testing, so I don't have a review for it. If it works for you and Kuzmany, that's good for me. |
Problem description
Currently it is very difficult to customize Mautic's editor (GrapesJS) to fit the requirements of a customer-project. The only way is to create a fork of grapesjs-preset-mautic, make the adjustments, re-compile the assets, and overwrite them inside the GrapesJsBuilderBundle. Especially for automatic deployments this is pretty much a huge hassle.
Solution proposal
The GrapesJS library has a plugin API (which grapesjs-preset-mautic uses also). We just need a way to allow other plugins being loaded additionally beside Mautic's changes of the editor. This PR does exactly that: other custom GrapesJS plugins (e.g. distributed through a custom plugin-bundle) can register itself in a place where Mautic's
builder.service
finds and adds them during initialization of the editor.Technical implementation
My main target was to find a simple and most-flexible solution for this problem with a very loose coupling. As inspiration I took the way of how GoogleAnalytics or other cliendside tracking-software using the so called Data-Layer to communicate with 3rd party scripts. This solution is basically bullet-proof easy because there is just one global
window
object through which all the communication runs. Its very loose coupled, only the loading-order matters (meaning, all plugins have loaded first before the actual editor is initialized). But using theAssetsSubscriber
, this is already the case.This PR modifies the
builder.service.js
to look for awindow.MauticGrapesJsPlugins
object (which holds an array of plugin-objects), and adding the plugins with its options to the editor on initializsation (if there are any).How to create and add a custom GrapesJS plugin
GrapesJsCustomPluginBundle
Because of the
export default
, this plugin can still be used in a fork customizing the source files withimport GrapesJsCustomPlugin from 'path'
. But this is not required! One can also write a plain vanialla JS function like described here.AssetSubscriber
of your plugin-bundle:The resulting HTML source looks like the following (the plugin code is loaded before
builder.js
, so its data is registered in the global window object):You can download this
GrapesJsCustomPluginBundle
for testing the PR here: https://github.com/Moongazer/GrapesJsCustomPluginBundleSummary
Just to sum up the main pros and cons of this solution:
Pros:
window.MauticGrapesJsPlugins
objectCons (not really):
window.MauticGrapesJsPlugins
(needs to be documented)grapesjs-preset-mautic
still a fork is requiredAnything else? Please feel free to discuss or improve the solution! Apprechiate any feedback.
Note:
If you want this feature in Mautic 4, you will need to apply this patch to your instance: #12692