Skip to content
Snippets Groups Projects
Commit 0c65ea19 authored by chris's avatar chris
Browse files

set Active

parent f4a8109e
No related branches found
No related tags found
1 merge request!348Multiple single
...@@ -15,7 +15,16 @@ const renderImage = file => { ...@@ -15,7 +15,16 @@ 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="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="1111111"><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="1111111">
<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 (
......
...@@ -324,7 +324,8 @@ export default css` ...@@ -324,7 +324,8 @@ export default css`
/* -- Multiple Choice ---------------------------------- */ /* -- Multiple Choice ---------------------------------- */
.multiple-choice { .multiple-choice,
.multiple-choice-single-correct {
border: 3px solid #f5f5f7; border: 3px solid #f5f5f7;
counter-reset: question-item-multiple; counter-reset: question-item-multiple;
margin: 38px; margin: 38px;
......
...@@ -62,7 +62,18 @@ class MultipleChoiceQuestion extends Tools { ...@@ -62,7 +62,18 @@ class MultipleChoiceQuestion extends Tools {
} }
get active() { get active() {
return state => {}; return state => {
let type = '';
const predicate = node =>
node.type === state.config.schema.nodes.multiple_choice;
for (let i = state.selection.$from.depth; i > 0; i--) {
const node = state.selection.$from.node(i);
if (predicate(node)) {
type = 'multiple';
}
}
return type;
};
} }
select = (state, activeView) => { select = (state, activeView) => {
......
...@@ -82,8 +82,6 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -82,8 +82,6 @@ const EditorComponent = ({ node, view, getPos }) => {
...plugins, ...plugins,
]); ]);
const { activeViewId } = context;
useEffect(() => { useEffect(() => {
questionView = new EditorView( questionView = new EditorView(
{ {
...@@ -100,14 +98,21 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -100,14 +98,21 @@ const EditorComponent = ({ node, view, getPos }) => {
disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'], disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'],
handleDOMEvents: { handleDOMEvents: {
mousedown: () => { mousedown: () => {
context.view[activeViewId].dispatch( context.view.main.dispatch(
context.view[activeViewId].state.tr.setSelection( context.view.main.state.tr.setSelection(
TextSelection.between( new TextSelection(
context.view[activeViewId].state.selection.$anchor, context.view.main.state.tr.doc.resolve(getPos() + 2),
context.view[activeViewId].state.selection.$head,
), ),
), ),
); );
// context.view[activeViewId].dispatch(
// context.view[activeViewId].state.tr.setSelection(
// TextSelection.between(
// context.view[activeViewId].state.selection.$anchor,
// context.view[activeViewId].state.selection.$head,
// ),
// ),
// );
context.updateView({}, questionId); context.updateView({}, questionId);
// Kludge to prevent issues due to the fact that the whole // Kludge to prevent issues due to the fact that the whole
// footnote is node-selected (and thus DOM-selected) when // footnote is node-selected (and thus DOM-selected) when
......
...@@ -62,7 +62,18 @@ class MultipleChoiceSingleCorrectQuestion extends Tools { ...@@ -62,7 +62,18 @@ class MultipleChoiceSingleCorrectQuestion extends Tools {
} }
get active() { get active() {
return state => {}; return state => {
let type = '';
const predicate = node =>
node.type === state.config.schema.nodes.multiple_choice_single_correct;
for (let i = state.selection.$from.depth; i > 0; i--) {
const node = state.selection.$from.node(i);
if (predicate(node)) {
type = 'multipleSingle';
}
}
return type;
};
} }
select = (state, activeView) => { select = (state, activeView) => {
......
...@@ -82,8 +82,6 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -82,8 +82,6 @@ const EditorComponent = ({ node, view, getPos }) => {
...plugins, ...plugins,
]); ]);
const { activeViewId } = context;
useEffect(() => { useEffect(() => {
questionView = new EditorView( questionView = new EditorView(
{ {
...@@ -100,11 +98,10 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -100,11 +98,10 @@ const EditorComponent = ({ node, view, getPos }) => {
disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'], disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'],
handleDOMEvents: { handleDOMEvents: {
mousedown: () => { mousedown: () => {
context.view[activeViewId].dispatch( context.view.main.dispatch(
context.view[activeViewId].state.tr.setSelection( context.view.main.state.tr.setSelection(
TextSelection.between( new TextSelection(
context.view[activeViewId].state.selection.$anchor, context.view.main.state.tr.doc.resolve(getPos() + 2),
context.view[activeViewId].state.selection.$head,
), ),
), ),
); );
......
...@@ -64,25 +64,37 @@ class MultipleDropDown extends ToolGroup { ...@@ -64,25 +64,37 @@ class MultipleDropDown extends ToolGroup {
const { state } = view; const { state } = view;
const dropDownOptions = [ const dropDownOptions = [
{ label: 'Multiple Choice ', value: '0', item: this._tools[0] },
{ {
label: 'Multiple Choice (single correct) ', label: 'Multiple Choice',
value: '0',
item: this._tools[0],
type: 'multiple',
},
{
label: 'Multiple Choice (single correct)',
value: '1', value: '1',
item: this._tools[1], item: this._tools[1],
type: 'multipleSingle',
},
{
label: 'True/False',
value: '2',
item: this._tools[0],
type: 'trueFalse',
}, },
{ label: 'True/False ', value: '2', item: this._tools[0] },
{ {
label: 'True/False (single correct) ', label: 'True/False (single correct)',
value: '3', value: '3',
item: this._tools[0], item: this._tools[0],
type: 'trueFalseSingle',
}, },
]; ];
const isDisabled = this._tools[0].select(state, activeView); const isDisabled = this._tools[0].select(state, activeView);
let found = ''; let found = '';
dropDownOptions.forEach((item, i) => { dropDownOptions.forEach((option, i) => {
if (item.item.select(state, activeView) === false) { if (option.item.active(main.state) === option.type) {
found = item.item.label; found = option.label;
} }
}); });
......
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