Newer
Older
import { findWrapping } from 'prosemirror-transform';
import { v4 as uuidv4 } from 'uuid';
import helpers from '../MultipleChoiceQuestionService/helpers/helpers';
title = 'Add Multiple Drop Down Question';
icon = 'mulitpleDropDownQuestion';
name = 'Multiple Drop Down';
get run() {
return main => {
const { dispatch } = main;
const { state } = main;
helpers.checkifEmpty(main);
const { $from, $to } = main.state.selection;
const wrapping =
range &&
findWrapping(
range,
state.config.schema.nodes.multiple_drop_down_container,
{
id: uuidv4(),
},
);
if (!wrapping) return false;
tr.wrap(range, wrapping);
dispatch(tr);
};
return state => {
if (
Commands.isParentOfType(
state,
state.config.schema.nodes.multiple_drop_down_container,
)
) {
return true;
}
return false;
};
select = (state, activeViewId, activeView) => {
const { disallowedTools } = activeView.props;
let status = true;
const { from, to } = state.selection;
if (from === null || disallowedTools.includes('MultipleDropDown'))
return false;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.groups.includes('questions')) {
status = false;
}
});
return status;
};