Editable Cell
Question
Hello, I am using GrapesJS for newsletters (with the gjs-preset-newsletter plugin) and i have a problem when I import code. I can't edit the boxes of type 'cell' (tds, trs...). I read it is a parameter and try to change it, unsuccessfully. Is there a way to do it without changing the source code?
Answers (3)
my solution:
editor.Components.addType('cell', {
isComponent(el) {
if (!(['td', 'th'].indexOf(el.tagName?.toLowerCase()) >= 0)) {
return false;
}
const allChildNodes: Node[] = [];
function collectChildNodes(arr: Node) {
const { childNodes } = arr;
if (childNodes.length > 0) {
for (let index = 0; index < childNodes.length; index += 1) {
const arrayChildNode = childNodes[index];
if (arrayChildNode.childNodes?.length > 0) {
collectChildNodes(arrayChildNode);
} else {
allChildNodes.push(arrayChildNode);
}
}
} else {
allChildNodes.push(arr);
}
}
collectChildNodes(el);
return !allChildNodes.every(
(item) => item.nodeType === 3 || item.nodeName?.toLowerCase() === 'br',
);
},
});
collect all childNodes, if all childNode is textNode or br element,I think it is not a td, back to a Text Wrapper and the user can edit the content
You should wrap the text in some other tag. If you can't change the content you should probably have to extend the original component Eg. inside isComponent make some kind of change
isComponent(el) {
let result = '';
const tag = el.tagName;
if (tag == 'TD' || tag == 'TH') {
result = {
type: 'cell',
tagName: tag.toLowerCase()
};
if ( /* eg. el has one textnode element */ ) {
result.components = `<div>${el.innerText}</div>`
}
}
return result;
}
I have same issue, Waiting for the answer.... #1257
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2076
[QUESTION] How make a new component to allow laravel blade directives?
Hi, thanks for the nice work. I'll like to know if there is a way to use blade directives inside the code. I already add a new functionalit...
Issue #837
[QUESTION] Javascript Deletes
Whenever I import, using import plugin, javascript part of the code is deleted. Is there any way to preserve it? I want to used the exporte...
Issue #3177
QUESTION/FEATURE REQUEST: Changing Selected Component Tooltip
Is there a way through the api to change the selected component tooltip or is that something that can only be done by editing the source? I...
Issue #3022
Localization without using "import"
Hi, to do localization is there a way to do it without using "import" ie with <script src="myFolder/grapesjs/locale/it.js"></script>? From...
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.