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

add essay question node

parent 959f5b4b
No related branches found
No related tags found
1 merge request!355Essay question
...@@ -70,7 +70,7 @@ const Editors = () => { ...@@ -70,7 +70,7 @@ const Editors = () => {
case 'ncbi': case 'ncbi':
return <NCBI />; return <NCBI />;
default: default:
return <Editoria />; return <HHMI />;
} }
}; };
......
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import { wrapIn } from 'prosemirror-commands'; import { wrapIn } from 'prosemirror-commands';
import { v4 as uuidv4 } from 'uuid';
import Tools from '../lib/Tools'; import Tools from '../lib/Tools';
@injectable() @injectable()
...@@ -11,7 +12,9 @@ class EssayQuestion extends Tools { ...@@ -11,7 +12,9 @@ class EssayQuestion extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
wrapIn(state.config.schema.nodes.essay)(state, dispatch); wrapIn(state.config.schema.nodes.essay, {
id: uuidv4(),
})(state, dispatch);
}; };
} }
......
...@@ -45,6 +45,7 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -45,6 +45,7 @@ const EditorComponent = ({ node, view, getPos }) => {
const editorRef = useRef(); const editorRef = useRef();
const context = useContext(WaxContext); const context = useContext(WaxContext);
const { activeViewId } = context;
let questionView; let questionView;
const questionId = node.attrs.id; const questionId = node.attrs.id;
const isEditable = context.view.main.props.editable(editable => { const isEditable = context.view.main.props.editable(editable => {
...@@ -98,21 +99,14 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -98,21 +99,14 @@ const EditorComponent = ({ node, view, getPos }) => {
disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'], disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'],
handleDOMEvents: { handleDOMEvents: {
mousedown: () => { mousedown: () => {
context.view.main.dispatch( context.view[activeViewId].dispatch(
context.view.main.state.tr.setSelection( context.view[activeViewId].state.tr.setSelection(
new TextSelection( TextSelection.between(
context.view.main.state.tr.doc.resolve(getPos() + 2), context.view[activeViewId].state.selection.$anchor,
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
......
/* eslint-disable react/prop-types */
import React from 'react'; import React from 'react';
import EditorComponent from './EditorComponent';
export default ({ node, view, getPos }) => { export default ({ node, view, getPos }) => {
return <span>Essay</span>; return <EditorComponent getPos={getPos} node={node} view={view} />;
}; };
const essayNode = { const essayNode = {
attrs: { attrs: {
class: { default: 'essay' }, class: { default: 'essay' },
id: { default: '' },
}, },
group: 'block questions', group: 'block questions',
atom: true,
selectable: true, selectable: true,
draggable: true, draggable: true,
content: 'block+', content: 'block+',
......
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