Skip to content
Snippets Groups Projects
Commit 7a57c16b authored by chris's avatar chris
Browse files

fix-history

parent 4186a6c1
No related branches found
No related tags found
1 merge request!307Answer nodeview
...@@ -18,18 +18,6 @@ const checkifEmpty = view => { ...@@ -18,18 +18,6 @@ const checkifEmpty = view => {
}); });
}; };
const createQuestion = (state, dispatch, tr, context) => {
const newAnswerId = uuidv4();
const answerOption = state.config.schema.nodes.multiple_choice.create(
{ id: newAnswerId },
Fragment.empty,
);
dispatch(tr.replaceSelectionWith(answerOption));
setTimeout(() => {
helpers.createEmptyParagraph(context, newAnswerId);
}, 100);
};
@injectable() @injectable()
class MultipleChoiceQuestion extends Tools { class MultipleChoiceQuestion extends Tools {
title = 'Add Multiple Choice Question'; title = 'Add Multiple Choice Question';
...@@ -41,28 +29,30 @@ class MultipleChoiceQuestion extends Tools { ...@@ -41,28 +29,30 @@ class MultipleChoiceQuestion extends Tools {
checkifEmpty(view); checkifEmpty(view);
const { state, dispatch } = view; const { state, dispatch } = view;
const { from, to } = state.selection;
const { tr } = state; const { tr } = state;
/* Create Wrapping */
let { $from, $to } = state.selection;
let range = $from.blockRange($to),
wrapping =
range &&
findWrapping(
range,
state.config.schema.nodes.multiple_choice_container,
{},
);
if (!wrapping) return false;
if (dispatch) tr.wrap(range, wrapping).scrollIntoView();
state.doc.nodesBetween(from, to, (node, pos) => { /* create First Option */
if (node.type.name === 'multiple_choice_container') { const newAnswerId = uuidv4();
createQuestion(state, dispatch, tr, context); const answerOption = state.config.schema.nodes.multiple_choice.create(
} else { { id: newAnswerId },
let { $from, $to } = state.selection; Fragment.empty,
let range = $from.blockRange($to), );
wrapping = dispatch(tr.replaceSelectionWith(answerOption));
range && setTimeout(() => {
findWrapping( helpers.createEmptyParagraph(context, newAnswerId);
range, }, 100);
state.config.schema.nodes.multiple_choice_container,
{},
);
if (!wrapping) return false;
if (dispatch) tr.wrap(range, wrapping).scrollIntoView();
createQuestion(state, dispatch, tr, context);
}
});
}; };
} }
......
import { v4 as uuidv4 } from 'uuid';
import { TextSelection } from 'prosemirror-state'; import { TextSelection } from 'prosemirror-state';
import { Fragment } from 'prosemirror-model';
const createEmptyParagraph = (context, newAnswerId) => { const createEmptyParagraph = (context, newAnswerId) => {
if (context.view[newAnswerId]) { if (context.view[newAnswerId]) {
......
...@@ -5,7 +5,7 @@ const multipleChoiceNode = { ...@@ -5,7 +5,7 @@ const multipleChoiceNode = {
feedback: { default: false }, feedback: { default: false },
}, },
group: 'block', group: 'block',
content: 'block+', content: 'block*',
// atom: true, // atom: true,
toDOM: node => ['multiple-choice', node.attrs, 0], toDOM: node => ['multiple-choice', node.attrs, 0],
parseDOM: [ parseDOM: [
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment