I'm new to stack exchange. I hope my question is not to long.
I want to integrate an inline tinymce editor in a component and use it in a gutenberg block. But my editors ui conflicts with gutenberg. (first screenshot)
The editor-element is inside a backbone view. I can’t use the RichText editor component in my case.
Background:
I‘m developing a plugin to insert leaflet maps into a post https://github.com/jhotadhari/geo-masala
The Plugin has a Gutenberg block to insert and control a map and its appearance/popups/controls/markers… .
Map-Features (Markers/Lines/Polygons) are saved as a custom-post-type: geom_feature. Each geom_feature has meta for geoJSON, appearance... The custom-post-type is registered without ui. All crud actions for geom_feature(s) are done within a gutenberg block (eg. drawing a marker creates a new geom_feature)
Inside the block, one component renders a leaflet map into a ref element. The component uses backbone to fetch the geom_feature(s) as a collection. When a Map-Feature (Leaflet.layer) is clicked, a toolbar opens with different editing options. The popup content can be edited within a popup (using a backform form with a custom wysiwyg field). The popup content is the post-content of the geom_feature.
The custom wysiwyg field uses a tinymce inline editor. All (eg updating new content to database) works fine, but the ui of that editor breaks. The editor toolbar and widgets are not in place.
I can init the editor with a fixed_toolbar_container. Like this:
initMceEditor: function(){
let self = this;
if ( this.mceEditor )
return this;
// setup editor element
this.getMceElement().attr( 'id', this.cid );
// setup toolbar element
this.setupToolbar();
let settings = _.extend( {}, wp.editor.getDefaultSettings().tinymce, {
selector: this.cid,
inline: true,
toolbar1: [
'formatselect fontsizeselect bold italic underline',
'bullist numlist',
'alignleft aligncenter alignright',
'link pastetext',
].join(' | '),
toolbar: true,
fixed_toolbar_container: '#geom-inline-editor-toolbar-' + this.cid,
content_css: geomData.pluginDirUrl + '/css/tinymce_content.min.css',
setup: function (editor) {
// editor events
// ... some lines skipped
},
});
// init mceEditor
this.mceEditor = tinymce.createEditor( this.cid, settings );
// render mceEditor
this.mceEditor.render();
return this;
},
This works but the appearance of the toolbar is not as expected. And mce panels and tooltips are displayed at the end of the document. See the first screenshot.
I can apply some style to fix this:
.geom-toolbar {
display: table;
width: 100%;
position: relative;
.geom-inline-editor-toolbar {
width: 100%;
.mce-flow-layout-item {
float: left;
}
.mce-widget.mce-btn {
float: left;
button {
padding: 0;
}
}
}
}
// stupid fix, dont do that!
.mce-widget.mce-tooltip[role="presentation"] {
position: absolute;
background-color: #111;
padding: 0.5em;
}
.mce-container.mce-panel.mce-floatpanel {
position: absolute;
max-width: 200px;
width: 200px !important;
}
The Editor looks like this then:
That’s not a good solution at all. And it will conflict somewhere.
Back to the Question
Does someone knows a way, to include an inline tinymce editor that doesn’t conflict with gutenberg?
Do I have to load some default styles for my tinymce editor that are not loaded by gutenberg? And how to limit their scope to my components Or can advise me way.
I don't search for a solution that uses gutenbergs RichText component.
Thank you