[BUG] Component from custom plugin is not recognized
Question
OS: Windows 10 x64
Browser: Chrome 72.0.3626.121 x64
GrapesJS: v0.14.55
Hello, I have some custom components (bootstrap tabs) in a plugin, for some reason some of the components of the plugin are not being detected by GrapesJS when loading it from the container elements, and others via dragging and dropping into the editor.
### This Component is not being detected:
const defaultType = dc.getType('default');
const defaultModel = defaultType.model;
const defaultView = defaultType.view;
const {tabPanesName, tabPaneSelector} = constants;
const classId = config.classTabPanes;
const type = tabPanesName;
dc.addType(type, {
model: defaultModel.extend({
defaults: {
...defaultModel.prototype.defaults,
name: 'Tab Content',
copyable: 0,
draggable: true,
droppable: tabPaneSelector,
},
}, {
isComponent(el) {
if (elHasClass(el, 'tab-content')) {
return {type};
}
},
}),
view: {removed because too big for issue},
});
### But this one is:
const defaultType = dc.getType('default');
const defaultModel = defaultType.model;
const defaultView = defaultType.view;
const { navigationName, tabSelector } = constants;
const type = navigationName;
dc.addType(type, {
model: defaultModel.extend({
defaults: {
...defaultModel.prototype.defaults,
name: 'Navigation',
copyable: 0,
draggable: true,
droppable: tabSelector,
traits: [
{
type: 'class_select',
options: [
{value: 'nav-tabs', name: 'Tabs'},
{value: 'nav-pills', name: 'Pills'},
],
label: 'Type',
},
{
type: 'class_select',
options: [
{value: '', name: 'Left'},
{value: 'nav-fill', name: 'Fill'},
{value: 'nav-justified', name: 'Justify'},
],
label: 'Layout',
},
],
},
}, {
isComponent(el) {
if (el.className && el.getAttribute('role') === 'tablist') {
return {type};
}
},
}),
view: {removed because too big for issue},
});
### Init code
var editor = grapesjs.init({
height: '100%',
showOffsets: 1,
noticeOnUnload: 0,
storageManager: { autoload: 0 },
container: '#gjs',
fromElement: true,
showDevices: false,
plugins: ['grapesjs-blocks-bootstrap4'],
pluginsOpts: {
'grapesjs-blocks-bootstrap4': {
blocks: {},
blockCategories: {},
labels: {},
gridDevicesPanel: true,
formPredefinedActions: [
{name: 'Contact', value: '/contact'},
{name: 'landing', value: '/landing'},
]
}
},
canvas: {
styles: [
'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css'
],
scripts: [
'https://code.jquery.com/jquery-3.3.1.slim.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js',
'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js'
],
}
});
window.editor = editor;
### HTML
This is the HTML thats inside the #gjs element and that GrapesJS should parse into components:
<div class="container">
<!-- Tab navigation -->
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home" role="tab">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#profile" role="tab">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#messages" role="tab">Messages</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#settings" role="tab">Settings</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="home" role="tabpanel">Home</div>
<div class="tab-pane" id="profile" role="tabpanel">Profile</div>
<div class="tab-pane" id="messages" role="tabpanel">Messages</div>
<div class="tab-pane" id="settings" role="tabpanel">Settings</div>
</div>
</div>
</div>
### Problem
The problem seems to be in the isComponent(el) method, the "el" parameter is never that particular element so it never returns the valid type.
What could the issue be?Answers (3)
As you see, its type is div... this is why it never reaches the other type... look why and where that type is declared
Alright, that was the issue! I thought that the 'div' type was a default one set by GrapesJS. Thanks for all the help!
It might be that elHasClass method?!?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1985
[BUG] Autosave with remote storage doesn't send network requests
OS: Windows 10 Browser: Chrome 73 GrapesJS version: 0.14.57 I have remote storage configured using this call to grapesjs.init(): While I se...
Issue #1756
Drag and Drop not working in resized editor window in Google Chrome
Hi, I developed some components and all works fine in Firefox, Opera browser. In Google chrome also working fine in fullscreen editor mode...
Issue #1658
[BUG] Checkbox trait does not load as checked even when the trait value is true
Hi, I'm using Grapesjs version 0.14.33. I'm loading some components when the form loads and I have a component with a checkbox trait. When...
Issue #871
[BUG] Wrong stylemanager options first time a component/block is selected
Hello, I have noticed the following buggy behaviour on the style manager:Using a local copy of GrapesJS (ver 0.14.5) . Tested in Chrome and...
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.