Newer
Older
import React from 'react';
import { isEmpty } from 'lodash';
import { Commands, DocumentHelpers, Tools } from 'wax-prosemirror-core';
import checkLevelFromConfig from '../HeadingService/checkLevelFromConfig';
Commands.setBlockType(state.config.schema.nodes.title, { level: 1 })(
state,
dispatch,
);
return Commands.blockActive(state.config.schema.nodes.title)(state);
};
}
const {
selection: { $from, $to },
} = state;
if (this.config) {
const allowedLevel = checkLevelFromConfig(
state,
activeViewId,
this.config,
);
if (allowedLevel > 1) return false;
}
const titleCounter = DocumentHelpers.findChildrenByType(
state.doc,
state.config.schema.nodes.title,
true,
);
if (
activeViewId !== 'main' ||
$from.parent !== $to.parent ||
titleCounter.length === 1
)
return false;
return Commands.setBlockType(state.config.schema.nodes.title)(state);
renderTool(view) {
if (isEmpty(view)) return null;
return this.isDisplayed() ? (
<TitleButton item={this.toJSON()} key="Title" view={view} />