Issue #2862πŸ’¬ AnsweredOpened Jun 29, 2020by Lerdouille0 reactions

Custom type unrecognized on import

Quick answerby Lerdouille

Hi, for the record, when i try to change the isComponent return, with a type defined in a plugin like this : isComponent: el => { if (el.tagName === 'DIV' && (typeof el.classList !== 'undefined' && el.classList.contains('imagelink-class'))) { return { type: 'marketing-button' }; } }, the import will recognize my <div>...

Read full answer below ↓

Question

Hi, i succeed to create a new type containing a clickable image. But unfortunaltely, the new custom type isn't recognize by the HTML parser on import. Here is my new type source code : editor.DomComponents.addType('imagelink', { isComponent: el => { if (el.tagName === 'DIV' && (typeof el.classList !== 'undefined' && el.classList.contains('imagelink-class'))) { return { type: 'imagelink' }; } }, model: { defaults: { tagName: 'div', resizable: {keepAutoHeight: true}, attributes: {class: 'imagelink-class', "data-type": "imagelink"}, droppable: false, traits: [ { type: 'href', label: 'Source', na...

Answers (3)

Lerdouilleβ€’ Jul 2, 2020

Hi, for the record, when i try to change the isComponent return, with a type defined in a plugin like this : isComponent: el => { if (el.tagName === 'DIV' && (typeof el.classList !== 'undefined' && el.classList.contains('imagelink-class'))) { return { type: 'marketing-button' }; } }, the import wil...

Lerdouilleβ€’ Jul 2, 2020

Another curiosity which might be logical... If i tried to put a exotic isComponent function like this : if (el.tagName === 'ABCDE') { return { type: 'imagelink' }; } And when i try to import this html text : <abcde>test</abcde> The plugin detect correctly my "imagelink" custom type. BUT, when i imp...

artfβ€’ Jul 6, 2020

I think you're missing the point of components. You have a custom one (imagelink) and then an inner one (img), so the editor shows it, so I see no issues here. To see the traits from the custom component you have to select it and it has nothing to do with the inner image

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.