Issue #1262Opened July 5, 2018by algodata445 reactions

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)

cody1991April 10, 20234 reactions

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

artfJuly 11, 20181 reactions

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;
    }
Shah-aliJuly 6, 20180 reactions

I have same issue, Waiting for the answer.... #1257

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.