renderSettings(): HTMLElement {
const wrapper: HTMLElement = el('div');
const selectTypeButton: HTMLSpanElement = el('span', null, {
innerHTML: 'Add FAQ',
});
selectTypeButton.addEventListener('click', () => {
const nextBlockId = this.$config.initialData.layout.children.length + 1;
this.$config.initialData.itemContent[nextBlockId] = {
blocks: [
{
data: {
text: 'Test' + nextBlockId,
level: 2,
},
type: 'Header',
},
{
data: {
text: 'Test' + nextBlockId,
},
type: 'paragraph',
},
],
};
this.$config.initialData.layout.children.push({
type: "item",
id: "",
className: "",
style: "border: 1px solid #000000; display: inline-block; ",
itemContentId: nextBlockId,
});
this.renderWrapper();
console.log(this.$config);
});
wrapper.appendChild(selectTypeButton);
return wrapper;
}
What I'm doing. I extending base class and making own:
import LayoutBlock from './layout-block';
import {el} from './block';
import EditorJS from "@editorjs/editorjs";
// @ts-ignore
import Header from '@editorjs/header';
class FaqBlock extends LayoutBlock {
/**
* @override
*/
static get toolbox() {
return {
title: 'FAQ',
icon: '<svg width="25" height="25" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><use xlink:href="/images/editor/faq.svg#faq"></use></svg>',
};
}
renderSettings(): HTMLElement {
const wrapper: HTMLElement = el('div');
const selectTypeButton: HTMLSpanElement = el('span', null, {
innerHTML: 'Add FAQ',
});
selectTypeButton.addEventListener('click', () => {
const nextBlockId = this.$config.initialData.layout.children.length + 1;
this.$config.initialData.itemContent[nextBlockId] = {
blocks: [
{
data: {
text: 'Test' + nextBlockId,
level: 2,
},
type: 'Header',
},
{
data: {
text: 'Test' + nextBlockId,
},
type: 'paragraph',
},
],
};
this.$config.initialData.layout.children.push({
type: "item",
id: "",
className: "",
style: "border: 1px solid #000000; display: inline-block; ",
itemContentId: nextBlockId,
});
this.renderWrapper();
console.log(this.$config);
});
wrapper.appendChild(selectTypeButton);
return wrapper;
}
}
// @ts-ignore
const editorJSConfig = typeof editorjsConfigs !== 'undefined' ? editorjsConfigs : null;
editorJSConfig.tools = {Header};
export default {
class: FaqBlock,
config: {
EditorJS,
editorJSConfig,
enableLayoutEditing: false,
enableLayoutSaving: true,
initialData: {
itemContent: {
1: {
blocks: [
{
data: {
text: 'Test',
level: 2,
},
type: 'Header',
},
{
data: {
text: 'Test',
},
type: 'paragraph',
},
],
},
},
layout: {
type: "container",
id: "",
className: "",
style: "border: 1px solid #000000; ",
children: [
{
type: "item",
id: "",
className: "",
style: "border: 1px solid #000000; display: inline-block; ",
itemContentId: "1",
},
],
},
},
},
};