Issue #1013✓ SolvedOpened April 7, 2018by tommedema5 reactions

Allow editing text nodes

快速解答by mipierce3

Read full answer below ↓

Question

Issue: text nodes that do not have a parent are not editable. Text nodes that have a parent but also have a sibling (e.g. a span), are also not editable. Support for raw text nodes is necessary.

Example that doesn't work:

<div id="gjs">
  <div class="glyphicon glyphicon-asterisk"></div> Try to edit me
</div>

Expected behavior is that the text node Try to edit me can be edited. Actual behavior is that it cannot be edited.

JSFiddle to reproduce: https://jsfiddle.net/szLp8h4n/107/

Answers (3)

👍 Most helpfulmipierceFebruary 4, 2021
// This is to fix text that isn't wrapped in a span to make the component editable
                        const updateLooseTextComponents = function(components: [any]) {
                            for (const component of components) {
                                if (component.type === 'textnode') {
                                    component.type = 'text';
                                    component.tagName = 'span';
                                }
                                if (component.components) {
                                    updateLooseTextComponents(component.components);
                                }
                            }
                        };

                        updateLooseTextComponents(components);

                        const td = template.template_data as any;
                        td['gjs-components'] = JSON.stringify(components);
tommedemaApril 15, 2018

@artf <gjs-text-node> seems like a good solution!

artfApril 9, 2018

Aware and agree, the question is just How?. Text nodes don't have contentEditable property, so probably we need to try to wrap them all inside <span>s (only in its View) and see how all is handled

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.