diff --git a/editors/demo/src/HHMI/config/config.js b/editors/demo/src/HHMI/config/config.js index 6bccceac3d3174a198098fb70c9dca1d896ce8a1..930b1815f8bef0cfc5391a665aceddda479ca202 100644 --- a/editors/demo/src/HHMI/config/config.js +++ b/editors/demo/src/HHMI/config/config.js @@ -22,16 +22,14 @@ import { BottomInfoService, MultipleChoiceQuestionService, MultipleChoiceToolGroupService, + FillTheGapQuestionService, + FillTheGapToolGroupService, } from 'wax-prosemirror-services'; import { DefaultSchema } from 'wax-prosemirror-utilities'; import { WaxSelectionPlugin } from 'wax-prosemirror-plugins'; import invisibles, { hardBreak } from '@guardian/prosemirror-invisibles'; -/* Questions Services */ -import FillTheGapQuestionService from '../FillTheGapQuestionService/FillTheGapQuestionService'; -import FillTheGapToolGroupService from '../FillTheGapToolGroupService/FillTheGapToolGroupService'; - export default { MenuService: [ { diff --git a/wax-prosemirror-services/index.js b/wax-prosemirror-services/index.js index 0e2ade71e55640153a98817d1933aa2cf3fdea24..6c7521803bd681e05cfa66f27b96eb55bd9cf89c 100644 --- a/wax-prosemirror-services/index.js +++ b/wax-prosemirror-services/index.js @@ -45,6 +45,7 @@ export { default as CustomTagInlineService } from './src/CustomTagService/Custom export { default as CustomTagBlockService } from './src/CustomTagService/CustomTagBlockService/CustomTagBlockService'; export { default as CustomTagService } from './src/CustomTagService/CustomTagService'; export { default as MultipleChoiceQuestionService } from './src/MultipleChoiceQuestionService/MultipleChoiceQuestionService'; +export { default as FillTheGapQuestionService } from './src/FillTheGapQuestionService/FillTheGapQuestionService'; /* ToolGroups @@ -71,3 +72,4 @@ export { default as TrackCommentOptionsToolGroupService } from './src/WaxToolGro export { default as CustomTagInlineToolGroupService } from './src/WaxToolGroups/CustomTagToolGroupService/CustomTagInlineToolGroupService/CustomTagInlineToolGroupService'; export { default as CustomTagBlockToolGroupService } from './src/WaxToolGroups/CustomTagToolGroupService/CustomTagBlockToolGroupService/CustomTagBlockToolGroupService'; export { default as MultipleChoiceToolGroupService } from './src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoiceToolGroupService'; +export { default as FillTheGapToolGroupService } from './src/WaxToolGroups/FillTheGapToolGroupService/FillTheGapToolGroupService'; diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/CreateGapService/CreateGap.js b/wax-prosemirror-services/src/FillTheGapQuestionService/CreateGapService/CreateGap.js similarity index 95% rename from editors/demo/src/HHMI/FillTheGapQuestionService/CreateGapService/CreateGap.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/CreateGapService/CreateGap.js index 5c45bfd0f429574a9552e23c7bd0fc2e2f921f9b..ba353bf6c827c90fd77f4c4485b0a29835cbcfc6 100644 --- a/editors/demo/src/HHMI/FillTheGapQuestionService/CreateGapService/CreateGap.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/CreateGapService/CreateGap.js @@ -1,7 +1,7 @@ import { injectable } from 'inversify'; import { Fragment } from 'prosemirror-model'; import { v4 as uuidv4 } from 'uuid'; -import { Tools } from 'wax-prosemirror-services'; +import Tools from '../../lib/Tools'; @injectable() class CreateGap extends Tools { diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/CreateGapService/CreateGapService.js b/wax-prosemirror-services/src/FillTheGapQuestionService/CreateGapService/CreateGapService.js similarity index 79% rename from editors/demo/src/HHMI/FillTheGapQuestionService/CreateGapService/CreateGapService.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/CreateGapService/CreateGapService.js index 02083ffd0698b8a6c44f02b656e3f8c8cadd67f2..6194a63fa67e18d4fd7b036cc94070371591b43e 100644 --- a/editors/demo/src/HHMI/FillTheGapQuestionService/CreateGapService/CreateGapService.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/CreateGapService/CreateGapService.js @@ -1,4 +1,4 @@ -import { Service } from 'wax-prosemirror-services'; +import Service from '../../Service'; import CreateGap from './CreateGap'; class FillTheGapQuestionService extends Service { diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapNodeView.js b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapNodeView.js similarity index 95% rename from editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapNodeView.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapNodeView.js index f1c34d5c63fa79a8bf7d19f400e023db7d59bedf..59b626c9ee42bb8793e788f28f9e2a0198308178 100644 --- a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapNodeView.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapNodeView.js @@ -1,4 +1,4 @@ -import { AbstractNodeView } from 'wax-prosemirror-services'; +import AbstractNodeView from '../PortalService/AbstractNodeView'; export default class MultipleChoiceNodeView extends AbstractNodeView { constructor( diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapQuestion.js b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestion.js similarity index 93% rename from editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapQuestion.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestion.js index 185e010126139e8bee5714763f0d7b31c0dfb6c6..36041c3d5e321f1e86b03ce6d00c66e3d6dbe46c 100644 --- a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapQuestion.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestion.js @@ -1,6 +1,6 @@ import { injectable } from 'inversify'; import { wrapIn } from 'prosemirror-commands'; -import { Tools } from 'wax-prosemirror-services'; +import Tools from '../lib/Tools'; @injectable() class FillTheGapQuestion extends Tools { diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapQuestionService.js b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestionService.js similarity index 94% rename from editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapQuestionService.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestionService.js index 8863042c88fc76ad6acdd0f82f40d318464f94e9..4c378b7d81906831564039a854b2936649efa149 100644 --- a/editors/demo/src/HHMI/FillTheGapQuestionService/FillTheGapQuestionService.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestionService.js @@ -1,4 +1,4 @@ -import { Service } from 'wax-prosemirror-services'; +import Service from '../Service'; import FillTheGapQuestion from './FillTheGapQuestion'; import fillTheGapContainerNode from './schema/fillTheGapContainerNode'; import fillTheGapNode from './schema/fillTheGapNode'; @@ -26,6 +26,7 @@ class FillTheGapQuestionService extends Service { context: this.app, }); } + dependencies = [new CreateGapService()]; } diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/components/EditorComponent.js b/wax-prosemirror-services/src/FillTheGapQuestionService/components/EditorComponent.js similarity index 93% rename from editors/demo/src/HHMI/FillTheGapQuestionService/components/EditorComponent.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/components/EditorComponent.js index e20129df2c48df10d811b861d4a5c8612c1b4e30..4e63e7f069b5d0f6edc293c723181151b33acedf 100644 --- a/editors/demo/src/HHMI/FillTheGapQuestionService/components/EditorComponent.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/components/EditorComponent.js @@ -1,6 +1,6 @@ /* eslint-disable react/destructuring-assignment */ /* eslint-disable react/prop-types */ -/* eslint-disable react-hooks/exhaustive-deps */ + import React, { useContext, useRef, useEffect } from 'react'; import styled from 'styled-components'; import { EditorView } from 'prosemirror-view'; @@ -116,7 +116,7 @@ const EditorComponent = ({ node, view, getPos }) => { }, ); - //Set Each note into Wax's Context + // Set Each note into Wax's Context context.updateView( { [questionId]: gapView, @@ -127,15 +127,15 @@ const EditorComponent = ({ node, view, getPos }) => { }, []); const dispatchTransaction = tr => { - let { state, transactions } = gapView.state.applyTransaction(tr); + const { state, transactions } = gapView.state.applyTransaction(tr); gapView.updateState(state); context.updateView({}, questionId); if (!tr.getMeta('fromOutside')) { - let outerTr = view.state.tr, - offsetMap = StepMap.offset(getPos() + 1); + const outerTr = view.state.tr; + const offsetMap = StepMap.offset(getPos() + 1); for (let i = 0; i < transactions.length; i++) { - let steps = transactions[i].steps; + const { steps } = transactions[i]; for (let j = 0; j < steps.length; j++) outerTr.step(steps[j].map(offsetMap)); } diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/components/GapComponent.js b/wax-prosemirror-services/src/FillTheGapQuestionService/components/GapComponent.js similarity index 63% rename from editors/demo/src/HHMI/FillTheGapQuestionService/components/GapComponent.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/components/GapComponent.js index 0169b0491882ccbc8539c208a353dafca7f90bad..efc17d00e85d22f08872143943820c9a7851260f 100644 --- a/editors/demo/src/HHMI/FillTheGapQuestionService/components/GapComponent.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/components/GapComponent.js @@ -1,12 +1,7 @@ +/* eslint-disable react/prop-types */ import React from 'react'; -import styled from 'styled-components'; import EditorComponent from './EditorComponent'; -const Gap = styled.span` - color: red; - text-decoration: underline; -`; - export default ({ node, view, getPos }) => { return <EditorComponent getPos={getPos} node={node} view={view} />; }; diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/schema/fillTheGapContainerNode.js b/wax-prosemirror-services/src/FillTheGapQuestionService/schema/fillTheGapContainerNode.js similarity index 100% rename from editors/demo/src/HHMI/FillTheGapQuestionService/schema/fillTheGapContainerNode.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/schema/fillTheGapContainerNode.js diff --git a/editors/demo/src/HHMI/FillTheGapQuestionService/schema/fillTheGapNode.js b/wax-prosemirror-services/src/FillTheGapQuestionService/schema/fillTheGapNode.js similarity index 100% rename from editors/demo/src/HHMI/FillTheGapQuestionService/schema/fillTheGapNode.js rename to wax-prosemirror-services/src/FillTheGapQuestionService/schema/fillTheGapNode.js diff --git a/editors/demo/src/HHMI/FillTheGapToolGroupService/FillTheGap.js b/wax-prosemirror-services/src/WaxToolGroups/FillTheGapToolGroupService/FillTheGap.js similarity index 100% rename from editors/demo/src/HHMI/FillTheGapToolGroupService/FillTheGap.js rename to wax-prosemirror-services/src/WaxToolGroups/FillTheGapToolGroupService/FillTheGap.js diff --git a/editors/demo/src/HHMI/FillTheGapToolGroupService/FillTheGapToolGroupService.js b/wax-prosemirror-services/src/WaxToolGroups/FillTheGapToolGroupService/FillTheGapToolGroupService.js similarity index 100% rename from editors/demo/src/HHMI/FillTheGapToolGroupService/FillTheGapToolGroupService.js rename to wax-prosemirror-services/src/WaxToolGroups/FillTheGapToolGroupService/FillTheGapToolGroupService.js diff --git a/wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoice.js b/wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoice.js new file mode 100644 index 0000000000000000000000000000000000000000..ec4920997bf8fcaa72037b70950b89e583ee3d30 --- /dev/null +++ b/wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoice.js @@ -0,0 +1,13 @@ +import { injectable, inject } from 'inversify'; +import ToolGroup from '../../lib/ToolGroup'; + +@injectable() +class MultipleChoice extends ToolGroup { + tools = []; + constructor(@inject('MultipleChoiceQuestion') multipleChoiceQuestion) { + super(); + this.tools = [multipleChoiceQuestion]; + } +} + +export default MultipleChoice; diff --git a/wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoiceToolGroupService.js b/wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoiceToolGroupService.js new file mode 100644 index 0000000000000000000000000000000000000000..8f13fbedd31ed32ca52eda9920497e7466cfeab7 --- /dev/null +++ b/wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoiceToolGroupService.js @@ -0,0 +1,10 @@ +import Service from '../../Service'; +import MultipleChoice from './MultipleChoice'; + +class MultipleChoiceToolGroupService extends Service { + register() { + this.container.bind('MultipleChoice').to(MultipleChoice); + } +} + +export default MultipleChoiceToolGroupService;