Newer
Older
import { injectable } from 'inversify';
import { isEmpty } from 'lodash';
import { LeftSideButton } from 'wax-prosemirror-components';
import { Commands } from 'wax-prosemirror-utilities';
import Tools from '../../lib/Tools';
class Heading2 extends Tools {
title = 'Change to heading level 2';
Commands.setBlockType(state.config.schema.nodes.heading, { level: 2 })(
return (state, activeViewId) => {
let isActive = true;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (
node.type.name === 'list_item' ||
node.type.name === 'image' ||
node.type.name === 'figure' ||
node.type.name === 'figcaption'
) {
isActive = false;
}
});
if (!isActive) return false;
return !Commands.setBlockType(state.config.schema.nodes.heading, {
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
};
return Commands.setBlockType(state.config.schema.nodes.heading, {
renderTool(view) {
if (isEmpty(view)) return null;
// eslint-disable-next-line no-underscore-dangle
return this._isDisplayed ? (
<LeftSideButton item={this.toJSON()} key="BlockQuote" view={view} />
) : null;
}