From 6e08282cca731ce1309ace05f24fdd82acf3f704 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Thu, 14 Oct 2021 19:42:46 +0300 Subject: [PATCH] move to services --- editors/demo/src/HHMI/config/config.js | 6 ++---- wax-prosemirror-services/index.js | 2 ++ .../CreateGapService/CreateGap.js | 2 +- .../CreateGapService/CreateGapService.js | 2 +- .../FillTheGapQuestionService/FillTheGapNodeView.js | 2 +- .../FillTheGapQuestionService/FillTheGapQuestion.js | 2 +- .../FillTheGapQuestionService.js | 3 ++- .../components/EditorComponent.js | 12 ++++++------ .../components/GapComponent.js | 7 +------ .../schema/fillTheGapContainerNode.js | 0 .../schema/fillTheGapNode.js | 0 .../FillTheGapToolGroupService/FillTheGap.js | 0 .../FillTheGapToolGroupService.js | 0 .../MultipleChoice.js | 13 +++++++++++++ .../MultipleChoiceToolGroupService.js | 10 ++++++++++ 15 files changed, 40 insertions(+), 21 deletions(-) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/CreateGapService/CreateGap.js (95%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/CreateGapService/CreateGapService.js (79%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/FillTheGapNodeView.js (95%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/FillTheGapQuestion.js (93%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/FillTheGapQuestionService.js (94%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/components/EditorComponent.js (93%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/components/GapComponent.js (63%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/schema/fillTheGapContainerNode.js (100%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src}/FillTheGapQuestionService/schema/fillTheGapNode.js (100%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src/WaxToolGroups}/FillTheGapToolGroupService/FillTheGap.js (100%) rename {editors/demo/src/HHMI => wax-prosemirror-services/src/WaxToolGroups}/FillTheGapToolGroupService/FillTheGapToolGroupService.js (100%) create mode 100644 wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoice.js create mode 100644 wax-prosemirror-services/src/WaxToolGroups/MultipleChoiceToolGroupService/MultipleChoiceToolGroupService.js diff --git a/editors/demo/src/HHMI/config/config.js b/editors/demo/src/HHMI/config/config.js index 6bccceac3..930b1815f 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 0e2ade71e..6c7521803 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 5c45bfd0f..ba353bf6c 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 02083ffd0..6194a63fa 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 f1c34d5c6..59b626c9e 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 185e01012..36041c3d5 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 8863042c8..4c378b7d8 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 e20129df2..4e63e7f06 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 0169b0491..efc17d00e 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 000000000..ec4920997 --- /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 000000000..8f13fbedd --- /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; -- GitLab