How to change gjs-ckeditor-format component
@vatte21 To make your component editable.You've to extend the text type in your component like this way
Read full answer below βQuestion
hi guys, we all know that gjs-ckeditor-plugin working with [data-gjs-type]="text" components. I wanna know , could we change this option? I want to make my own custom component with for example [data-gjs-type]="anyDiv" and have the same functionality like in [data-gjs-type]="text". maybe someone knows how to change that? maybe i can change that in ckeditor config? when we initialize ckeditor for example: options: { !!!!!for example: format: 'text' , want to add ('anyDiv'), language: 'en', startupFocus: true, extraAllowedContent: '();{}', // Allows any class and any inline style allowedContent: true, // Disable auto-formatting, class removing, etc. enterMode: ckeditor.ENTER_BR, uiColor: '#0000001a', // Inline editor color extraPlugins: 'justify,colorbutton,panelbutton,font,sourcedialog,showblocks', height: 5, toolbar:[ [ "Format", 'Font', 'FontSize',"-", "Bold", "Italic", "Strike", "Underline", "Subscript", "Superscript", "RemoveFormat", "-", "-", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock", "-", "TextColor", "BGColor", "-", "-", "-"] ] }, position: 'left',
Answers (4)
@vatte21 To make your component editable.You've to extend the text type in your component like this way
editor.Components.addType('anyDiv', {
model: {
defaults: {
type: 'text',
traits:[
...editor.Components.getType(type.id).model.prototype.defaults.traits,
...[]
]
},
reRender() {
this.view.render();
},
},
extend: 'text',
isComponent: function (el) {
if (el.tagName === 'anyDiv')
return {type: 'anyDiv'};
}
});
@Abhisheknanda1344463 Thank you! Ill try
@Abhisheknanda1344463 your code fragment gives me an error Uncaught ReferenceError: type is not defined on the line
...editor.Components.getType(type.id).model.prototype.defaults.traits,
where is type defined?
Thanks for reporting this, @vatte21.
Great suggestion about how to change gjs-ckeditor-format component! While this specific feature isn't yet in the core API, there are several ways to achieve similar behavior.
Using the event system:
editor.on('component:update', (component) => {
// your logic here
});
Alternative approaches:
- Listen to
selector:addfor CSS selector changes - Use
selector:customfor custom rules - Tap into the
change:*events for fine-grained tracking - Build a plugin that extends the editor with this capability
Making it official: If this feature would benefit many users, consider opening a formal Feature Request on the GrapesJS repo with:
- A detailed use case
- Code example showing the desired behavior
- Why this matters for your workflow
The core team is receptive to well-motivated feature requests backed by real use cases.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3486
FEAT: Ability to change all margin, padding etc properties together
Hello, right now grapesjs provides built in properties like margin, padding that allow user to change each property one by one (margin-top,...
Issue #5199
Changes in component's attributes being reproduced in all the instances instead of just one
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v114 Reproducible demo link https:/...
Issue #3832
The css classes are removed and the autogenerated ids for each html tags gets changed ( Example : ivj5m-2) after each reload
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link Not there De...
Issue #4225
BUG : The facebook plugin is not working in the grapes js
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome v9Reproducible demo link Not thereDes...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Tutorial
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins β TinyMCE Inline Text Editor and Placeholder.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.