CKEditor blocks is not editable[QUESTION]
Question
Hi guys, I added the custom CKEditor blocks and its working fine. but the actual issues is I can't able to delete, move or add the traits in the CKEditor blocks. I tried all the possible but nothing is work. I really stuck. can anyone please help me.
my custom blocks:
editor.BlockManager.add('ckeditor', {
id: 'ckeditor',
label: `fa fa-check-square`,
category: 'Basic',
content: `
<textarea data-gjs-type="ckeditor5" data-rte="1" name="content" id="ckeditor">This is some sample content.</textarea>
`,
draggable: true,
removable: true
});
my traits:-
const comps = editor.DomComponents;
const defaultType = comps.getType('default');
const defaultModel = defaultType.model;
comps.addType(buttonName, {
model: defaultModel.extend({
defaults: Object.assign({}, defaultModel.prototype.defaults, {
draggable: '*',
droppable: false,
script: function () {
const initCKeditor = function () {
ClassicEditor.create(document.querySelector('#ckeditor'))
.then(obj => {
console.log(obj);
})
.catch(error => {
console.error(error);
});
};
if (typeof ClassicEditor === 'undefined') {
const script = document.createElement('script');
script.onload = initCKeditor;
script.src = 'https://cdn.ckeditor.com/ckeditor5/11.2.0/classic/ckeditor.js';
document.body.appendChild(script);
} else {
initCKeditor();
}
},
traits: [{
label: 'name',
name: 'name',
changeProp: 1,
type: 'text'
}],
})
},
{
isComponent: function (el) {
if (el.tagName === buttonName) {
return {
type: buttonName
};
}
},
}),
// Define the View
view: defaultType.view,
});
}

as you can see the above image that I only able to select the div but not the textarea.
Answers (2)
Well, the textarea can't be selected because it's a static element generated from you component's script so it's not part of the editor, it's all correct.
If your point is to change internal CKEditor configurations you have to rely on your component traits and use string interpolations inside your script (like described in docs)
// ...
script: function () {
const config1 = '{[ propertyName1 ]}';
const config2 = '{[ propertyName2 ]}';
const initCKeditor = function () {
// ...
BTW don't do this ClassicEditor.create(document.querySelector('#ckeditor'))
in this way your integration will break with multiple components of the same time.
I think it would be better for you to update your stuff in this way
// I'm using the new API for component type definition, you should do the same...
defaults: {
draggable: '*',
droppable: false,
// Default component content
components: '<textarea>This is some sample content.</textarea>',
script: function () {
// ...
const textareaEl = this.firstChild;
ClassicEditor.create(textareaEl);
}
//
editor.BlockManager.add('ckeditor', {
// ...
content: { type: 'ckeditor5' },
});
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1720
[QUESTION] How to add the button in custom traits
Hi, I try to add a button to my custom traits for my custom blocks but its not working fine as expected and also need to know how to call t...
Issue #2400
Is it possible to 'toggle' a button added within Panel from function outside of GJS?
Hi Guys, Firstly awesome project, have really enjoyed extending GJS to work with our use case - and am excited for what's in store looking...
Issue #1806
[Feature]: Add category on traits
Hi and thank's for your job ! It's possible to make traits under cateogories like blocks ? If it's possible, maybe use the Category object...
Issue #3214
Ckeditor Enable for header type
Hi @artf I've added the CKEditor in the grapesjs and it's working fine but the problem is on the header-block CKEditor is not showing up I'...
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.