Skip to content
Snippets Groups Projects
Commit 091758ba authored by chris's avatar chris
Browse files

move to commands and start from service

parent 0c65ea19
No related branches found
No related tags found
1 merge request!348Multiple single
......@@ -21,7 +21,6 @@ import {
EditorInfoToolGroupServices,
BottomInfoService,
MultipleChoiceQuestionService,
MultipleChoiceSingleCorrectQuestionService,
MultipleChoiceToolGroupService,
FillTheGapQuestionService,
FillTheGapToolGroupService,
......@@ -69,7 +68,6 @@ export default {
],
services: [
new MultipleChoiceSingleCorrectQuestionService(),
new FillTheGapQuestionService(),
new FillTheGapToolGroupService(),
new MultipleChoiceQuestionService(),
......
......@@ -63,16 +63,10 @@ class MultipleChoiceQuestion extends Tools {
get active() {
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;
return Commands.isParentOfType(
state,
state.config.schema.nodes.multiple_choice,
);
};
}
......
......@@ -4,6 +4,7 @@ import multipleChoiceNode from './schema/multipleChoiceNode';
import multipleChoiceContainerNode from './schema/multipleChoiceContainerNode';
import QuestionComponent from './components/QuestionComponent';
import MultipleChoiceNodeView from './MultipleChoiceNodeView';
import MultipleChoiceSingleCorrectQuestionService from '../MultipleChoiceSingleCorrectQuestionService/MultipleChoiceSingleCorrectQuestionService';
class MultipleChoiceQuestionService extends Service {
register() {
......@@ -25,6 +26,8 @@ class MultipleChoiceQuestionService extends Service {
context: this.app,
});
}
dependencies = [new MultipleChoiceSingleCorrectQuestionService()];
}
export default MultipleChoiceQuestionService;
......@@ -63,16 +63,10 @@ class MultipleChoiceSingleCorrectQuestion extends Tools {
get active() {
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;
return Commands.isParentOfType(
state,
state.config.schema.nodes.multiple_choice_single_correct,
);
};
}
......
......@@ -68,32 +68,28 @@ class MultipleDropDown extends ToolGroup {
label: 'Multiple Choice',
value: '0',
item: this._tools[0],
type: 'multiple',
},
{
label: 'Multiple Choice (single correct)',
value: '1',
item: this._tools[1],
type: 'multipleSingle',
},
{
label: 'True/False',
value: '2',
item: this._tools[0],
type: 'trueFalse',
},
{
label: 'True/False (single correct)',
value: '3',
item: this._tools[0],
type: 'trueFalseSingle',
},
// {
// label: 'True/False',
// value: '2',
// item: this._tools[0],
// },
// {
// label: 'True/False (single correct)',
// value: '3',
// item: this._tools[0],
// },
];
const isDisabled = this._tools[0].select(state, activeView);
let found = '';
dropDownOptions.forEach((option, i) => {
if (option.item.active(main.state) === option.type) {
if (option.item.active(main.state)) {
found = option.label;
}
});
......
......@@ -14,6 +14,7 @@
},
"dependencies": {
"prosemirror-commands": "1.1.10",
"prosemirror-transform": "1.2.6",
"prosemirror-utils": "^0.9.6",
"uuid": "^7.0.3"
}
......
......@@ -240,7 +240,7 @@ const createCommentOnFootnote = (state, dispatch, group, viewid) => {
const isInTable = state => {
const { $head } = state.selection;
for (let d = $head.depth; d > 0; d--)
for (let d = $head.depth; d > 0; d -= 1)
if ($head.node(d).type.spec.tableRole === 'row') return true;
return false;
};
......@@ -253,6 +253,18 @@ const simulateKey = (view, keyCode, key) => {
return view.someProp('handleKeyDown', f => f(view, event));
};
const isParentOfType = (state, nodeType) => {
let status = false;
const predicate = node => node.type === nodeType;
for (let i = state.selection.$from.depth; i > 0; i -= 1) {
const node = state.selection.$from.node(i);
if (predicate(node)) {
status = true;
}
}
return status;
};
export default {
isInTable,
setBlockType,
......@@ -265,4 +277,5 @@ export default {
markActive,
isOnSameTextBlock,
simulateKey,
isParentOfType,
};
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