Skip to content
Snippets Groups Projects
Commit 6b81fb26 authored by chris's avatar chris
Browse files

use helpers

parent 9e4c0cad
No related branches found
No related tags found
1 merge request!526new wrapper component
...@@ -6,22 +6,9 @@ import { Fragment } from 'prosemirror-model'; ...@@ -6,22 +6,9 @@ import { Fragment } from 'prosemirror-model';
import { TextSelection } from 'prosemirror-state'; import { TextSelection } from 'prosemirror-state';
import { findWrapping } from 'prosemirror-transform'; import { findWrapping } from 'prosemirror-transform';
import { Commands, Tools } from 'wax-prosemirror-core'; import { Commands, Tools } from 'wax-prosemirror-core';
import helpers from '../MultipleChoiceQuestionService/helpers/helpers';
import ToolBarBtn from './components/ToolBarBtn'; import ToolBarBtn from './components/ToolBarBtn';
const checkifEmpty = view => {
const { state } = view;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, node => {
if (node.textContent !== ' ') Commands.simulateKey(view, 13, 'Enter');
});
if (state.selection.constructor.name === 'GapCursor') {
Commands.simulateKey(view, 13, 'Enter');
setTimeout(() => {
view.focus();
});
}
};
const createEmptyParagraph = (context, newAnswerId) => { const createEmptyParagraph = (context, newAnswerId) => {
const { pmViews } = context; const { pmViews } = context;
...@@ -63,16 +50,16 @@ class EssayQuestion extends Tools { ...@@ -63,16 +50,16 @@ class EssayQuestion extends Tools {
get run() { get run() {
return (main, context) => { return (main, context) => {
checkifEmpty(main); helpers.checkifEmpty(main);
const { state, dispatch } = main; const { state, dispatch } = main;
/* Create Wrapping */ /* Create Wrapping */
const { $from, $to } = state.selection; const { $from, $to } = state.selection;
const range = $from.blockRange($to); const range = $from.blockRange($to);
const { tr } = main.state; const { tr } = state;
const wrapping = const wrapping =
range && range &&
findWrapping(range, main.state.config.schema.nodes.essay_container, { findWrapping(range, state.config.schema.nodes.essay_container, {
id: uuidv4(), id: uuidv4(),
}); });
if (!wrapping) return false; if (!wrapping) return false;
...@@ -86,16 +73,16 @@ class EssayQuestion extends Tools { ...@@ -86,16 +73,16 @@ class EssayQuestion extends Tools {
tr.setSelection(TextSelection.create(tr.doc, range.$to.pos)); tr.setSelection(TextSelection.create(tr.doc, range.$to.pos));
const essayQuestion = main.state.config.schema.nodes.essay_question.create( const essayQuestion = state.config.schema.nodes.essay_question.create(
{ id: uuidv4() }, { id: uuidv4() },
Fragment.empty, Fragment.empty,
); );
const essayPrompt = main.state.config.schema.nodes.essay_prompt.create( const essayPrompt = state.config.schema.nodes.essay_prompt.create(
{ id: uuidv4() }, { id: uuidv4() },
Fragment.empty, Fragment.empty,
); );
const essayAnswer = main.state.config.schema.nodes.essay_answer.create( const essayAnswer = state.config.schema.nodes.essay_answer.create(
{ id: uuidv4() }, { id: uuidv4() },
Fragment.empty, Fragment.empty,
); );
......
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