BUG: Non-named plugins and options
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
all and none, the bug is during the build
Reproducible demo link
unnecessary
Describe the bug
How to reproduce the bug?
Use NPM to install GrapesJS to use it in a typescript project.
According to the documentation, to set options of an non-named plugin, we have to defined this in init:
plugins: [myPlugin],
pluginsOpts: {
[myPlugin]: {
customField: 'customValue'
}
}
What is the expected behavior? The build of the project works
What is the current behavior?
The build failed with this error: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
FYI We can use a named plugin but this way of doing is mark as 'Deprecated' in favor of the non-named version and can't be used for official plugins which are provided as non-named
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (3)
This seems to be related to https://github.com/microsoft/TypeScript/issues/35945 As a workaround you could do something like this for now:
pluginsOpts: {
[myPlugin.toString()]: {
customField: 'customValue'
}
}
I guess for the TS type safety we would need to introduce some kind of helper for plugins
import grapesjs, { usePlugin } from 'grapesjs';
import somePlugin from 'gjs-plugin';
grapesjs.init({
// ...
plugins: [
// no need for `pluginsOpts`
usePlugin(somePlugin, { option1: 'A', option2: 'B', ... })
]
});
that sounds to be a good idea
Added the helper here (I'll also update the docs with the usage later)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5148
BUG: none of the official GrapesJS plugins works with the new index.d.ts
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? all and none, the bug is during the build...
Issue #5593
BUG: Layer manager not refreshing on page change
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? MS Edge 120.0.2210.91 Reproducible demo li...
Issue #4921
BUG:
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 110.0.5481.78 (Official Bui...
Issue #5583
BUG: Can't set background:none in mobile version using styles panel
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Edge last version Reproducible demo link h...
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.