[QUESTION] Create custom selected component settings
Question
There is a option in panel to change setting of component (For links, there is an option no change link - HREF - and target, for texts, id and title and for images, alt attribute). I would like to know how can I create that inputs and how can I change this attrs in selected component? I created a Panel's view to use as CKEditor to change text components when selected and I would like that these otter settings be at the same view:
editor.Panels.addButton('views',{ // `views` is the panel's id
id: 'editorCK',
className: 'fa fa-pencil',
command: 'editorCK',
});
editor.Commands.add('editorCK', {
run: function(editor, sender){
const bm = editor.BlockManager;
const pn = editor.Panels;
var blocoSelecionado = editor.getSelected();
if(this.mkeditorCustom){
$(this.mkeditorCustom).remove();
}
if (blocoSelecionado && blocoSelecionado.attributes.type == "text"){
bm.render();
const id = 'views-container';
const mkeditorCustom = document.createElement('div');
const panels = pn.getPanel(id) || pn.addPanel({ id });
const textarea = document.createElement('textarea');
textarea.id = "ckeditor";
mkeditorCustom.appendChild(textarea);
panels.set('appendContent', mkeditorCustom).trigger('change:appendContent');
this.mkeditorCustom = mkeditorCustom;
$('#ckeditor').html(blocoSelecionado.toHTML().replace(/<div class="c.*?>(.*?)<\/div>/, '$1'));
if(CKEDITOR.instances.ckeditor) CKEDITOR.instances.ckeditor.destroy();
if(!CKEDITOR.instances.ckeditor) CKEDITOR.replace('ckeditor', opcoesCKEDITOR);
CKEDITOR.instances['ckeditor'].on('change', function() {
blocoSelecionado.set('content', CKEDITOR.instances['ckeditor'].getData().replace(/<div class="c.*?>(.*?)<\/div>/, '$1'));
});
}else{
bm.render();
const id = 'views-container';
const mkeditorCustom = document.createElement('div');
const panels = pn.getPanel(id) || pn.addPanel({ id });
const conteudo = document.createElement('div');
conteudo.className = 'gjs-sm-header';
const texto = document.createTextNode('Selecione um bloco de texto para usar o editor de texto');
conteudo.appendChild(texto);
mkeditorCustom.appendChild(conteudo);
panels.set('appendContent', mkeditorCustom).trigger('change:appendContent');
this.mkeditorCustom = mkeditorCustom;
}
this.mkeditorCustom.style.display = 'block';
},
stop: function(editor, sender){
if(CKEDITOR.instances['ckeditor']) CKEDITOR.instances['ckeditor'].destroy();
const mkeditorCustom = this.mkeditorCustom;
mkeditorCustom && (mkeditorCustom.style.display = 'none');
}
});
Other thing I'm trying to is create at this same Panel View is an input (when isn't any component selected) that change max width of html generated and another to change background's color
Answers (3)
@JulyanoF ,
Sorry, I missed the parenthesis.
It is editor.TraitManager.getTraitsViewer().el
Here is what you looking for: https://github.com/artf/grapesjs/wiki/Components
@arthuralmeidap ok, but how can I show the component in my current Command?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1144
[Question]: Custom property to change multiple settings
Is there a way to extend a current property or create a new one to change multiple properties? I have a component in which I would like to...
Issue #1324
Remove attributes from a component
Hi @artf I don't know if it is possible to remove an attribute from a component. In our project I'm injecting a custom attribute from a cus...
Issue #362
How to create custom link components that prompts users to type link/choose link similar to Images Component Modal
Image Components have logic to call Modal and prompt user's interaction for options/configuration of image url. Would like to do similar to...
Issue #794
[QUESTION] How to create a custom option in toolbox?
I would like to know how can I create a custom "option" with custom content in this place:
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.