diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js index da65af734fe06f3169b84b9277cb3f5b6e45a24a..bf84c981f8c7c76baf734b4adc6f5dfb378d16f3 100644 --- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js +++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js @@ -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() class MultipleChoiceQuestion extends Tools { title = 'Add Multiple Choice Question'; @@ -41,28 +29,30 @@ class MultipleChoiceQuestion extends Tools { checkifEmpty(view); const { state, dispatch } = view; - const { from, to } = state.selection; 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) => { - if (node.type.name === 'multiple_choice_container') { - createQuestion(state, dispatch, tr, context); - } else { - 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(); - - createQuestion(state, dispatch, tr, context); - } - }); + /* create First Option */ + 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); }; } diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/helpers/helpers.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/helpers/helpers.js index 4962ea2a999c7af343a3e8eb20a641aad507491e..74a6d96c5e5d4dd689ff16177e52c20f5809a984 100644 --- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/helpers/helpers.js +++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/helpers/helpers.js @@ -1,6 +1,4 @@ -import { v4 as uuidv4 } from 'uuid'; import { TextSelection } from 'prosemirror-state'; -import { Fragment } from 'prosemirror-model'; const createEmptyParagraph = (context, newAnswerId) => { if (context.view[newAnswerId]) { diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js index 61e6edde27220d27d4ce86afc98292a91c0836f2..10503330cf0bb5a76625b861b232273bc698baca 100644 --- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js +++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js @@ -5,7 +5,7 @@ const multipleChoiceNode = { feedback: { default: false }, }, group: 'block', - content: 'block+', + content: 'block*', // atom: true, toDOM: node => ['multiple-choice', node.attrs, 0], parseDOM: [