Skip to content
Snippets Groups Projects
Commit 84d84036 authored by chris's avatar chris
Browse files

true false question

parent c7371ba0
No related branches found
No related tags found
1 merge request!356Question in nodeview
import AbstractNodeView from '../../PortalService/AbstractNodeView';
export default class QuestionNodeView extends AbstractNodeView {
constructor(
node,
view,
getPos,
decorations,
createPortal,
Component,
context,
) {
super(node, view, getPos, decorations, createPortal, Component, context);
this.node = node;
this.outerView = view;
this.getPos = getPos;
this.context = context;
}
static name() {
return 'question_node_true_false';
}
update(node) {
this.node = node;
if (this.context.view[node.attrs.id]) {
const { state } = this.context.view[node.attrs.id];
const start = node.content.findDiffStart(state.doc.content);
if (start != null) {
let { a: endA, b: endB } = node.content.findDiffEnd(state.doc.content);
const overlap = start - Math.min(endA, endB);
if (overlap > 0) {
endA += overlap;
endB += overlap;
}
this.context.view[node.attrs.id].dispatch(
state.tr
.replace(start, endB, node.slice(start, endA))
.setMeta('fromOutside', true),
);
}
}
return true;
}
stopEvent(event) {
if (event.target.type === 'text') {
return true;
}
const innerView = this.context.view[this.node.attrs.id];
return innerView && innerView.dom.contains(event.target);
}
}
......@@ -19,8 +19,9 @@ class TrueFalseQuestion extends Tools {
helpers.createOptions(
view,
context,
view.state.config.schema.nodes.true_false,
view.state.config.schema.nodes.true_false_container,
view.state.config.schema.nodes.question_node_true_false,
view.state.config.schema.nodes.true_false,
);
};
}
......
import Service from '../../Service';
import TrueFalseQuestion from './TrueFalseQuestion';
import trueFalseNode from './schema/trueFalseNode';
import questionTrueFalseNode from './schema/questionTrueFalseNode';
import trueFalseContainerNode from './schema/trueFalseContainerNode';
import QuestionComponent from './components/QuestionComponent';
import AnswerComponent from './components/AnswerComponent';
import TrueFalseNodeView from './TrueFalseNodeView';
import QuestionTrueFalseNodeView from './QuestionTrueFalseNodeView';
import QuestionComponent from '../components/QuestionComponent';
class TrueFalseQuestionService extends Service {
register() {
......@@ -19,11 +22,21 @@ class TrueFalseQuestionService extends Service {
true_false: trueFalseNode,
});
createNode({
question_node_true_false: questionTrueFalseNode,
});
addPortal({
nodeView: TrueFalseNodeView,
nodeView: QuestionTrueFalseNodeView,
component: QuestionComponent,
context: this.app,
});
addPortal({
nodeView: TrueFalseNodeView,
component: AnswerComponent,
context: this.app,
});
}
}
......
import { v4 as uuidv4 } from 'uuid';
const questionTrueFalseNode = {
attrs: {
class: { default: 'true-false-question' },
id: { default: uuidv4() },
},
group: 'block questions',
content: 'block*',
defining: true,
// atom: true,
parseDOM: [
{
tag: 'div.true-false-question',
getAttrs(dom) {
return {
id: dom.getAttribute('id'),
class: dom.getAttribute('class'),
};
},
},
],
toDOM: node => ['div', node.attrs, 0],
};
export default questionTrueFalseNode;
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