Skip to content
Snippets Groups Projects
Commit fe3001f4 authored by Christos's avatar Christos
Browse files

Merge branch 'question-fixes' into 'master'

Question fixes

See merge request !332
parents 885dc499 7e4e1e29
No related branches found
No related tags found
1 merge request!332Question fixes
Showing
with 109 additions and 21 deletions
...@@ -15,7 +15,7 @@ const renderImage = file => { ...@@ -15,7 +15,7 @@ const renderImage = file => {
}); });
}; };
const t = `<p class="paragraph">Based on the equation below</p><math-display class="math-node">x + y = 5</math-display><p class="paragraph">Which ones are correct?</p><p class="paragraph"></p><div id="" class="mutiple-choice"><div class="mutiple-choice-option" id="d7b65415-ff82-446f-afa4-accaa3837f4a" correct="false" feedback=""><p class="paragraph">answer 1</p><p class="paragraph"><math-inline class="math-node">x+y=1</math-inline></p></div><div class="mutiple-choice-option" id="e7d6bb2f-7cd7-44f1-92a0-281e72157538" correct="true" feedback=""><p class="paragraph">answer 2</p></div><div class="mutiple-choice-option" id="d6fc749f-afae-4203-9562-d68c380a86e5" correct="false" feedback=""><p class="paragraph">answer 3</p></div></div><div id="" class="fill-the-gap"><p class="paragraph">A <span id="bfd4376c-4424-455e-9187-f53282fa1024" class="fill-the-gap">DNA</span> molecule is very long and usually consists of hundreds or thousands of genes.</p><p class="paragraph">An electron having a certain discrete amount of <span id="14dedf44-728f-4384-835f-e3af82b25623" class="fill-the-gap">energy</span> is something like a ball on a staircase.</p></div><p class="paragraph"></p>`; const t = `<p class="paragraph">Based on the equation below</p><math-display class="math-node">x + y = 5</math-display><p class="paragraph">Which ones are correct?</p><p class="paragraph"></p><div id="" class="multiple-choice"><div class="multiple-choice-option" id="d7b65415-ff82-446f-afa4-accaa3837f4a" correct="false" feedback=""><p class="paragraph">answer 1</p><p class="paragraph"><math-inline class="math-node">x+y=1</math-inline></p></div><div class="multiple-choice-option" id="e7d6bb2f-7cd7-44f1-92a0-281e72157538" correct="true" feedback=""><p class="paragraph">answer 2</p></div><div class="multiple-choice-option" id="d6fc749f-afae-4203-9562-d68c380a86e5" correct="false" feedback=""><p class="paragraph">answer 3</p></div></div><div id="" class="fill-the-gap"><p class="paragraph">A <span id="bfd4376c-4424-455e-9187-f53282fa1024" class="fill-the-gap">DNA</span> molecule is very long and usually consists of hundreds or thousands of genes.</p><p class="paragraph">An electron having a certain discrete amount of <span id="14dedf44-728f-4384-835f-e3af82b25623" class="fill-the-gap">energy</span> is something like a ball on a staircase.</p></div><p class="paragraph"></p>`;
const Hhmi = () => { const Hhmi = () => {
return ( return (
......
...@@ -325,7 +325,7 @@ export default css` ...@@ -325,7 +325,7 @@ export default css`
/* -- Multiple Choice ---------------------------------- */ /* -- Multiple Choice ---------------------------------- */
.mutiple-choice { .multiple-choice {
border: 3px solid #f5f5f7; border: 3px solid #f5f5f7;
counter-reset: question-item-multiple; counter-reset: question-item-multiple;
margin: 38px; margin: 38px;
......
...@@ -18,9 +18,12 @@ class FillTheGapQuestion extends Tools { ...@@ -18,9 +18,12 @@ class FillTheGapQuestion extends Tools {
return state => {}; return state => {};
} }
select = (state, activeViewId) => { select = (state, activeViewId, activeView) => {
let status = true; let status = true;
const { disallowedTools } = activeView.props;
const { from, to } = state.selection; const { from, to } = state.selection;
if (from === null || disallowedTools.includes('Lists')) return false;
state.doc.nodesBetween(from, to, (node, pos) => { state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.groups.includes('questions')) { if (node.type.groups.includes('questions')) {
status = false; status = false;
......
...@@ -91,7 +91,7 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -91,7 +91,7 @@ const EditorComponent = ({ node, view, getPos }) => {
}), }),
// This is the magic part // This is the magic part
dispatchTransaction, dispatchTransaction,
disallowedTools: ['images', 'lists', 'lift'], disallowedTools: ['Images', 'Lists', 'lift', 'Tables', 'FillTheGap'],
handleDOMEvents: { handleDOMEvents: {
mousedown: () => { mousedown: () => {
context.view[activeViewId].dispatch( context.view[activeViewId].dispatch(
......
...@@ -2,7 +2,8 @@ const fillTheGapNode = { ...@@ -2,7 +2,8 @@ const fillTheGapNode = {
group: 'inline', group: 'inline',
content: 'text*', content: 'text*',
inline: true, inline: true,
// atom: true, atom: true,
excludes: 'fill_the_gap',
attrs: { attrs: {
id: { default: '' }, id: { default: '' },
class: { default: 'fill-the-gap' }, class: { default: 'fill-the-gap' },
......
/* eslint-disable no-underscore-dangle */
import React from 'react'; import React from 'react';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
...@@ -19,8 +20,12 @@ class Image extends Tools { ...@@ -19,8 +20,12 @@ class Image extends Tools {
} }
select = activeView => { select = activeView => {
const {
selection: { from },
} = activeView.state;
if (from === null) return false;
const { disallowedTools } = activeView.props; const { disallowedTools } = activeView.props;
if (disallowedTools.includes('images')) return false; if (disallowedTools.includes('Images')) return false;
return true; return true;
}; };
...@@ -39,9 +44,9 @@ class Image extends Tools { ...@@ -39,9 +44,9 @@ class Image extends Tools {
); );
return this._isDisplayed ? ( return this._isDisplayed ? (
<ImageUpload <ImageUpload
key={uuidv4()}
item={this.toJSON()}
fileUpload={upload} fileUpload={upload}
item={this.toJSON()}
key={uuidv4()}
view={view} view={view}
/> />
) : null; ) : null;
......
...@@ -16,6 +16,14 @@ class Code extends Tools { ...@@ -16,6 +16,14 @@ class Code extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.code)(state); return Commands.markActive(state.config.schema.marks.code)(state);
......
...@@ -16,6 +16,14 @@ class Emphasis extends Tools { ...@@ -16,6 +16,14 @@ class Emphasis extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.em)(state); return Commands.markActive(state.config.schema.marks.em)(state);
......
...@@ -16,6 +16,14 @@ class SmallCaps extends Tools { ...@@ -16,6 +16,14 @@ class SmallCaps extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.smallcaps)(state); return Commands.markActive(state.config.schema.marks.smallcaps)(state);
......
...@@ -16,6 +16,14 @@ class StrikeThrough extends Tools { ...@@ -16,6 +16,14 @@ class StrikeThrough extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.strikethrough)( return Commands.markActive(state.config.schema.marks.strikethrough)(
......
import { toggleMark } from 'prosemirror-commands'; import { toggleMark } from 'prosemirror-commands';
import { Commands } from 'wax-prosemirror-utilities'; import { Commands } from 'wax-prosemirror-utilities';
import Tools from '../../lib/Tools';
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import Tools from '../../lib/Tools';
export default export default
@injectable() @injectable()
...@@ -16,6 +16,14 @@ class Strong extends Tools { ...@@ -16,6 +16,14 @@ class Strong extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.strong)(state); return Commands.markActive(state.config.schema.marks.strong)(state);
......
...@@ -16,6 +16,14 @@ class Subscript extends Tools { ...@@ -16,6 +16,14 @@ class Subscript extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.subscript)(state); return Commands.markActive(state.config.schema.marks.subscript)(state);
......
...@@ -16,6 +16,14 @@ class Superscript extends Tools { ...@@ -16,6 +16,14 @@ class Superscript extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.superscript)(state); return Commands.markActive(state.config.schema.marks.superscript)(state);
......
...@@ -17,6 +17,14 @@ class Underline extends Tools { ...@@ -17,6 +17,14 @@ class Underline extends Tools {
}; };
} }
select = state => {
const {
selection: { from },
} = state;
if (from === null) return false;
return true;
};
get active() { get active() {
return state => { return state => {
return Commands.markActive(state.config.schema.marks.underline)(state); return Commands.markActive(state.config.schema.marks.underline)(state);
......
...@@ -25,8 +25,12 @@ class BulletList extends Tools { ...@@ -25,8 +25,12 @@ class BulletList extends Tools {
} }
select = (state, activeViewId, activeView) => { select = (state, activeViewId, activeView) => {
const {
selection: { from },
} = state;
if (from === null) return false;
const { disallowedTools } = activeView.props; const { disallowedTools } = activeView.props;
if (disallowedTools.includes('lists')) return false; if (disallowedTools.includes('Lists')) return false;
return true; return true;
}; };
......
...@@ -23,8 +23,12 @@ class OrderedList extends Tools { ...@@ -23,8 +23,12 @@ class OrderedList extends Tools {
} }
select = (state, activeViewId, activeView) => { select = (state, activeViewId, activeView) => {
const {
selection: { from },
} = state;
if (from === null) return false;
const { disallowedTools } = activeView.props; const { disallowedTools } = activeView.props;
if (disallowedTools.includes('lists')) return false; if (disallowedTools.includes('Lists')) return false;
return true; return true;
}; };
......
...@@ -30,9 +30,14 @@ class MultipleChoiceQuestion extends Tools { ...@@ -30,9 +30,14 @@ class MultipleChoiceQuestion extends Tools {
return state => {}; return state => {};
} }
select = (state, activeViewId) => { select = (state, activeViewId, activeView) => {
const { disallowedTools } = activeView.props;
if (disallowedTools.includes('MultipleChoice')) return false;
let status = true; let status = true;
const { from, to } = state.selection; const { from, to } = state.selection;
if (from === null) return false;
state.doc.nodesBetween(from, to, (node, pos) => { state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.groups.includes('questions')) { if (node.type.groups.includes('questions')) {
status = false; status = false;
......
...@@ -97,7 +97,7 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -97,7 +97,7 @@ const EditorComponent = ({ node, view, getPos }) => {
}), }),
// This is the magic part // This is the magic part
dispatchTransaction, dispatchTransaction,
disallowedTools: ['images', 'lists', 'lift'], disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'],
handleDOMEvents: { handleDOMEvents: {
mousedown: () => { mousedown: () => {
context.view[activeViewId].dispatch( context.view[activeViewId].dispatch(
......
/* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable react/destructuring-assignment */
/* eslint-disable react/prop-types */
import React, { useContext, useRef, useState, useEffect } from 'react'; import React, { useContext, useRef, useState, useEffect } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { TextSelection } from 'prosemirror-state'; import { TextSelection } from 'prosemirror-state';
...@@ -44,7 +46,7 @@ export default ({ node, view, getPos }) => { ...@@ -44,7 +46,7 @@ export default ({ node, view, getPos }) => {
if (e.key === 'Backspace') { if (e.key === 'Backspace') {
context.view.main.dispatch( context.view.main.dispatch(
context.view.main.state.tr.setSelection( context.view.main.state.tr.setSelection(
new TextSelection(context.view.main.state.tr.doc.resolve(0)), TextSelection.create(context.view.main.state.tr.doc, 0),
), ),
); );
} }
...@@ -73,7 +75,7 @@ export default ({ node, view, getPos }) => { ...@@ -73,7 +75,7 @@ export default ({ node, view, getPos }) => {
const onFocus = () => { const onFocus = () => {
context.view.main.dispatch( context.view.main.dispatch(
context.view.main.state.tr.setSelection( context.view.main.state.tr.setSelection(
new TextSelection(context.view.main.state.tr.doc.resolve(0)), TextSelection.create(context.view.main.state.tr.doc, null),
), ),
); );
}; };
...@@ -82,14 +84,14 @@ export default ({ node, view, getPos }) => { ...@@ -82,14 +84,14 @@ export default ({ node, view, getPos }) => {
<FeedBack> <FeedBack>
<FeedBackLabel>Feedback</FeedBackLabel> <FeedBackLabel>Feedback</FeedBackLabel>
<FeedBackInput <FeedBackInput
onKeyDown={handleKeyDown} onBlur={saveFeedBack}
onChange={feedBackInput} onChange={feedBackInput}
onFocus={onFocus}
onKeyDown={handleKeyDown}
placeholder="Insert feedback" placeholder="Insert feedback"
ref={feedBackRef} ref={feedBackRef}
type="text" type="text"
value={feedBack} value={feedBack}
onBlur={saveFeedBack}
onFocus={onFocus}
/> />
</FeedBack> </FeedBack>
); );
......
...@@ -44,8 +44,8 @@ const ToolBarBtn = ({ view = {}, item }) => { ...@@ -44,8 +44,8 @@ const ToolBarBtn = ({ view = {}, item }) => {
const createOption = () => { const createOption = () => {
const { state, dispatch } = main; const { state, dispatch } = main;
/* Create Wrapping */ /* Create Wrapping */
let { $from, $to } = state.selection; const { $from, $to } = state.selection;
let range = $from.blockRange($to); const range = $from.blockRange($to);
wrapIn(state.config.schema.nodes.multiple_choice_container, { wrapIn(state.config.schema.nodes.multiple_choice_container, {
id: uuidv4(), id: uuidv4(),
......
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