diff --git a/editors/demo/src/HHMI/HHMI.js b/editors/demo/src/HHMI/HHMI.js index 19ab37c7bd3d70f8d215612b458ac567b67731be..1b9ce865f386cfeb6241f51e97f78f3652137516 100644 --- a/editors/demo/src/HHMI/HHMI.js +++ b/editors/demo/src/HHMI/HHMI.js @@ -167,11 +167,10 @@ const Hhmi = () => { ref={editorRef} customValues={{ showFeedBack: submitted, testMode }} fileUpload={file => renderImage(file)} - // value={content} - targetFormat="JSON" + value={content} readonly={readOnly} layout={HhmiLayout} - onChange={source => console.log(source)} + // onChange={source => console.log(source)} /> </> ); diff --git a/wax-questions-service/src/MultipleChoiceQuestionService/components/FeedbackComponent.js b/wax-questions-service/src/MultipleChoiceQuestionService/components/FeedbackComponent.js index 2cf40ab1e318a9d423175d9bffdec70aae3b1fbb..1634d5bcf22d5a3aae17c3190a6d3d9a78cdebe8 100644 --- a/wax-questions-service/src/MultipleChoiceQuestionService/components/FeedbackComponent.js +++ b/wax-questions-service/src/MultipleChoiceQuestionService/components/FeedbackComponent.js @@ -120,7 +120,8 @@ const getNodes = view => { node.node.type.name === 'true_false_single_correct' || node.node.type.name === 'matching_container' || node.node.type.name === 'fill_the_gap_container' || - node.node.type.name === 'multiple_drop_down_container' + node.node.type.name === 'multiple_drop_down_container' || + node.node.type.name === 'numerical_answer_container' ) { multipleChoiceNodes.push(node); } diff --git a/wax-questions-service/src/NumericalAnswerService/components/EditorComponent.js b/wax-questions-service/src/NumericalAnswerService/components/EditorComponent.js deleted file mode 100644 index 34d695e04776b56b059445793f9e90ba6acc7809..0000000000000000000000000000000000000000 --- a/wax-questions-service/src/NumericalAnswerService/components/EditorComponent.js +++ /dev/null @@ -1,226 +0,0 @@ -/* eslint-disable react/prop-types */ -import React, { useContext, useRef, useEffect } from 'react'; -import styled from 'styled-components'; -import { EditorView } from 'prosemirror-view'; -import { EditorState, TextSelection, NodeSelection } from 'prosemirror-state'; -import { StepMap } from 'prosemirror-transform'; -import { keymap } from 'prosemirror-keymap'; -import { baseKeymap, chainCommands } from 'prosemirror-commands'; -import { undo, redo } from 'prosemirror-history'; -import { WaxContext, ComponentPlugin } from 'wax-prosemirror-core'; -import { - splitListItem, - liftListItem, - sinkListItem, -} from 'prosemirror-schema-list'; -import Placeholder from '../../MultipleChoiceQuestionService/plugins/placeholder'; -import FakeCursorPlugin from '../../MultipleDropDownService/plugins/FakeCursorPlugin'; - -const EditorWrapper = styled.div` - border: none; - display: flex; - flex: 2 1 auto; - justify-content: left; - - .ProseMirror { - white-space: break-spaces; - width: 100%; - word-wrap: break-word; - - &:focus { - outline: none; - } - - :empty::before { - content: 'Type your question'; - color: #aaa; - float: left; - font-style: italic; - pointer-events: none; - } - - p:first-child { - margin: 0; - } - - p.empty-node:first-child::before { - content: attr(data-content); - } - - .empty-node::before { - color: rgb(170, 170, 170); - float: left; - font-style: italic; - height: 0px; - pointer-events: none; - } - } -`; - -let WaxOverlays = () => true; - -const EditorComponent = ({ - node, - view, - getPos, - placeholderText = 'Type your question', -}) => { - const editorRef = useRef(); - - const context = useContext(WaxContext); - const { - app, - pmViews: { main }, - } = context; - let questionView; - const questionId = node.attrs.id; - const isEditable = main.props.editable(editable => { - return editable; - }); - - let finalPlugins = [FakeCursorPlugin()]; - - const createKeyBindings = () => { - const keys = getKeys(); - Object.keys(baseKeymap).forEach(key => { - if (keys[key]) { - keys[key] = chainCommands(keys[key], baseKeymap[key]); - } else { - keys[key] = baseKeymap[key]; - } - }); - return keys; - }; - - const pressEnter = (state, dispatch) => { - if (state.selection.node && state.selection.node.type.name === 'image') { - const { $from, to } = state.selection; - - const same = $from.sharedDepth(to); - - const pos = $from.before(same); - dispatch(state.tr.setSelection(NodeSelection.create(state.doc, pos))); - return true; - } - // LISTS - if (splitListItem(state.schema.nodes.list_item)(state)) { - splitListItem(state.schema.nodes.list_item)(state, dispatch); - return true; - } - - return false; - }; - - const getKeys = () => { - return { - 'Mod-z': () => undo(view.state, view.dispatch), - 'Mod-y': () => redo(view.state, view.dispatch), - 'Mod-[': liftListItem(view.state.schema.nodes.list_item), - 'Mod-]': sinkListItem(view.state.schema.nodes.list_item), - // Enter: () => - // splitListItem(questionView.state.schema.nodes.list_item)( - // questionView.state, - // questionView.dispatch, - // ), - Enter: pressEnter, - }; - }; - - const plugins = [keymap(createKeyBindings()), ...app.getPlugins()]; - - const createPlaceholder = placeholder => { - return Placeholder({ - content: placeholder, - }); - }; - - finalPlugins = finalPlugins.concat([ - createPlaceholder(placeholderText), - ...plugins, - ]); - - useEffect(() => { - WaxOverlays = ComponentPlugin('waxOverlays'); - questionView = new EditorView( - { - mount: editorRef.current, - }, - { - editable: () => isEditable, - state: EditorState.create({ - doc: node, - plugins: finalPlugins, - }), - dispatchTransaction, - disallowedTools: ['MultipleChoice'], - handleDOMEvents: { - mousedown: () => { - context.updateView({}, questionId); - main.dispatch( - main.state.tr - .setMeta('outsideView', questionId) - .setSelection( - new TextSelection( - main.state.tr.doc.resolve( - getPos() + - 1 + - context.pmViews[questionId].state.selection.to, - ), - ), - ), - ); - - context.updateView({}, questionId); - - if (questionView.hasFocus()) questionView.focus(); - }, - blur: (editorView, event) => { - if (questionView && event.relatedTarget === null) { - questionView.focus(); - } - }, - }, - - attributes: { - spellcheck: 'false', - }, - }, - ); - - // Set Each note into Wax's Context - context.updateView( - { - [questionId]: questionView, - }, - questionId, - ); - if (questionView.hasFocus()) questionView.focus(); - }, []); - - const dispatchTransaction = tr => { - const { state, transactions } = questionView.state.applyTransaction(tr); - questionView.updateState(state); - context.updateView({}, questionId); - - if (!tr.getMeta('fromOutside')) { - const outerTr = view.state.tr; - const offsetMap = StepMap.offset(getPos() + 1); - for (let i = 0; i < transactions.length; i++) { - const { steps } = transactions[i]; - for (let j = 0; j < steps.length; j++) - outerTr.step(steps[j].map(offsetMap)); - } - if (outerTr.docChanged) - view.dispatch(outerTr.setMeta('outsideView', questionId)); - } - }; - - return ( - <EditorWrapper> - <div ref={editorRef} /> - <WaxOverlays activeViewId={questionId} /> - </EditorWrapper> - ); -}; - -export default EditorComponent; diff --git a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js index 6e8a582b7c1bdac6ea0a22978f42ca60020311c9..301951a86920be8123da0ef20fe2de53cc4c3b05 100644 --- a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js +++ b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js @@ -6,7 +6,7 @@ import { Icon, } from 'wax-prosemirror-core'; import styled from 'styled-components'; -import EditorComponent from './EditorComponent'; +import EditorComponent from '../../MultipleChoiceQuestionService/components/EditorComponent'; import FeedbackComponent from '../../MultipleChoiceQuestionService/components/FeedbackComponent'; const NumericalAnswerWrapper = styled.div` @@ -29,6 +29,8 @@ const NumericalAnswerContainerTool = styled.div` } `; +const NumericalAnswerOption = styled.div``; + const ActionButton = styled.button` background: transparent; cursor: pointer; @@ -95,7 +97,7 @@ export default ({ node, view, getPos }) => { </div> <NumericalAnswerContainer className="numerical-answer"> <EditorComponent getPos={getPos} node={node} view={view} /> - + <NumericalAnswerOption>Selected Option</NumericalAnswerOption> {!testMode && !(readOnly && feedback === '') && ( <FeedbackComponent getPos={getPos}