Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Draggable property added in the final HTML text components #2508

Closed
alexiswbr opened this issue Jan 14, 2020 · 5 comments
Closed

[Bug] Draggable property added in the final HTML text components #2508

alexiswbr opened this issue Jan 14, 2020 · 5 comments
Labels

Comments

@alexiswbr
Copy link

alexiswbr commented Jan 14, 2020

This bug is also on the online demo : https://grapesjs.com/demo.html

  1. Add a Text Block to the page, start typing and hiting enter to make several break lines.
  2. Unselect the block.
  3. Double click on the block to start editing again.

Now if you click on the "view code" button, you will see that the HTML nodes inside the Text Block have some draggable="true attributes.
This always occure at step three. The first time you edit the text and add break lines, everything is fine, as long as you do not want to edit the block again later.

The problem is, in the final HTML displayed on a website, these attributes are still there. You can not select anything because the navigator interpreting the draggable attributes.
And yes I am saving in database both of the html and components separately

It seems like a bug to me, or I misunderstood something else

draggable-html-bug-1
draggable-html-bug-2

@pouyamiralayi
Copy link

@alexiswbr using the below snippet, the div's will become br's as the expected behaviour:

var iframeBody = editor.Canvas.getBody();
	$(iframeBody).on("keydown", "[contenteditable]", e => {
		// trap the return key being pressed
		if (e.keyCode === 13) {
				e.preventDefault();
				// insert 2 br tags (if only one br tag is inserted the cursor won't go to the next line)
				e.target.ownerDocument.execCommand("insertHTML", false, "<br><br>");
				// prevent the default behaviour of return key pressed
				return false;
		}
	});

@obrazkow
Copy link

I use such way to prevent transformation to component and keep original html.
Just override component that you need, for example text or create new.

Maybe it's not good solution, but it works :)

export default (editor, type) => {
    const comps = editor.DomComponents;

    const typeToExtend = comps.getType(type);
    const modelToExtend = typeToExtend.model;

    comps.addType(type, {
        model: modelToExtend.extend({
            init() {
                if (modelToExtend.prototype.init) {
                    modelToExtend.prototype.init.apply(this, arguments);
                }

                const models = this.components().models;
                if (models.length) {
                    const elem = models.reduce((content, component) => {
                        content.append(component.get('rawContent') || component.get('content'));
                        return content;
                    }, document.createElement('div'));

                    for (let i = models.length; i !== 0; i--) {
                        models[i - 1].remove();
                    }

                    this.set({content: elem.innerHTML});
                }
            }
        }, {
            isComponent(el) {
                if (el && el.parentElement && el.parentElement.dataset && el.parentElement.dataset.gjsType === type) {
                    return {
                        type: type,
                        content: el,
                        rawContent: el,
                        tagName: 'raw_html'
                    };
                }

                return false;
            }
        }),

        view: typeToExtend.view
    });
}

@alexiswbr
Copy link
Author

Well these are some quick fix but there is another bug maybe linked to this one.
The more you click on the text component, the more the ids are duplicated and you end up with some HTML nodes having this kind of id : ilin-2-2-2-2-2-2-2-2-2-2-2-2.

@artf
Copy link
Member

artf commented Jan 18, 2020

Ok I'll try to check this out

@artf artf added the bug label Jan 18, 2020
@artf artf closed this as completed in 4b77caf Jan 23, 2020
@riteshagarwalsw
Copy link

riteshagarwalsw commented Jun 23, 2022

@artf The same issue exists in the latest online demo : https://grapesjs.com/demo.html
Please help me find a solution to the problem. Although it's marked fixed, but maybe because of some other code it's happening again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants