From feb91fd8a06d7cfd3b9e3556a8b35069ff37b27a Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 16 Mar 2022 11:27:45 +0200 Subject: [PATCH] nodeview plus schema files --- editors/demo/src/Editors.js | 2 +- editors/demo/src/HHMI/config/config.js | 5 +++ editors/demo/src/HHMI/layout/HhmiLayout.js | 2 +- .../MatchingContainerNodeView.js | 32 +++++++++++++++++++ .../src/MatchingService/MatchingQuestion.js | 6 ++-- .../src/MatchingService/MatchingService.js | 16 ++++++++-- .../schema/matchingContainerNode.js | 25 +++++++++++++++ .../MatchingToolGroupService/Matching.js | 4 +-- 8 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 wax-prosemirror-services/src/MatchingService/MatchingContainerNodeView.js create mode 100644 wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js diff --git a/editors/demo/src/Editors.js b/editors/demo/src/Editors.js index 166168897..1e839e3d3 100644 --- a/editors/demo/src/Editors.js +++ b/editors/demo/src/Editors.js @@ -70,7 +70,7 @@ const Editors = () => { case 'ncbi': return <NCBI />; default: - return <Editoria />; + return <HHMI />; } }; diff --git a/editors/demo/src/HHMI/config/config.js b/editors/demo/src/HHMI/config/config.js index be6033507..3257bebfd 100644 --- a/editors/demo/src/HHMI/config/config.js +++ b/editors/demo/src/HHMI/config/config.js @@ -27,6 +27,8 @@ import { MultipleDropDownToolGroupService, EssayService, EssayToolGroupService, + MatchingService, + MatchingToolGroupService, } from 'wax-prosemirror-services'; import { DefaultSchema } from 'wax-prosemirror-utilities'; @@ -55,6 +57,7 @@ export default { 'MultipleDropDown', 'Essay', 'FillTheGap', + 'Matching', 'FullScreen', ], }, @@ -66,6 +69,8 @@ export default { PmPlugins: [columnResizing(), tableEditing(), invisibles([hardBreak()])], services: [ + new MatchingService(), + new MatchingToolGroupService(), new FillTheGapQuestionService(), new FillTheGapToolGroupService(), new MultipleChoiceQuestionService(), diff --git a/editors/demo/src/HHMI/layout/HhmiLayout.js b/editors/demo/src/HHMI/layout/HhmiLayout.js index 6f57c434c..436f33949 100644 --- a/editors/demo/src/HHMI/layout/HhmiLayout.js +++ b/editors/demo/src/HHMI/layout/HhmiLayout.js @@ -48,7 +48,7 @@ const TopMenu = styled.div` margin-right: ${grid(5)}; } - > div[data-name='FillTheGap'] { + > div[data-name='Matching'] { border-right: none; } `; diff --git a/wax-prosemirror-services/src/MatchingService/MatchingContainerNodeView.js b/wax-prosemirror-services/src/MatchingService/MatchingContainerNodeView.js new file mode 100644 index 000000000..387c6ccc3 --- /dev/null +++ b/wax-prosemirror-services/src/MatchingService/MatchingContainerNodeView.js @@ -0,0 +1,32 @@ +import QuestionsNodeView from '../lib/helpers/QuestionsNodeView'; + +export default class MatchingContainerNodeView extends QuestionsNodeView { + 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 'matching_container'; + } + + stopEvent(event) { + if (event.target.type === 'text') { + return true; + } + const innerView = this.context.pmViews[this.node.attrs.id]; + return innerView && innerView.dom.contains(event.target); + } +} diff --git a/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js b/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js index a5f68685b..b23b840f1 100644 --- a/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js +++ b/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js @@ -3,9 +3,9 @@ import Tools from '../lib/Tools'; @injectable() class MatchingQuestion extends Tools { - title = 'Change to Block Quote'; - label = 'Block Quote'; - name = 'BlockQuote'; + title = 'Add Matching'; + label = 'Matching'; + name = 'Matching'; get run() { return (state, dispatch) => {}; diff --git a/wax-prosemirror-services/src/MatchingService/MatchingService.js b/wax-prosemirror-services/src/MatchingService/MatchingService.js index 2106442c4..83f1f0395 100644 --- a/wax-prosemirror-services/src/MatchingService/MatchingService.js +++ b/wax-prosemirror-services/src/MatchingService/MatchingService.js @@ -1,13 +1,25 @@ import Service from '../Service'; import MatchingQuestion from './MatchingQuestion'; +import matchingContainerNode from './schema/matchingContainerNode'; +import MatchingContainerNodeView from './MatchingContainerNodeView'; class MatchingService extends Service { name = 'MatchingService'; - boot() {} - register() { this.container.bind('MatchingQuestion').to(MatchingQuestion); + const createNode = this.container.get('CreateNode'); + const addPortal = this.container.get('AddPortal'); + + createNode({ + matching_container: matchingContainerNode, + }); + + // addPortal({ + // nodeView: MatchingContainerNodeView, + // component: QuestionComponent, + // context: this.app, + // }); } } diff --git a/wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js b/wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js new file mode 100644 index 000000000..f2d714604 --- /dev/null +++ b/wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js @@ -0,0 +1,25 @@ +const matchingContainerNode = { + attrs: { + id: { default: '' }, + class: { default: 'matching-container' }, + }, + group: 'block questions', + atom: true, + content: 'block*', + parseDOM: [ + { + tag: 'div.matching-container', + getAttrs(dom) { + return { + id: dom.getAttribute('id'), + class: dom.getAttribute('class'), + }; + }, + }, + ], + toDOM(node) { + return ['div', node.attrs, 0]; + }, +}; + +export default matchingContainerNode; diff --git a/wax-prosemirror-services/src/WaxToolGroups/MatchingToolGroupService/Matching.js b/wax-prosemirror-services/src/WaxToolGroups/MatchingToolGroupService/Matching.js index 3671ef6fd..497d3c5c2 100644 --- a/wax-prosemirror-services/src/WaxToolGroups/MatchingToolGroupService/Matching.js +++ b/wax-prosemirror-services/src/WaxToolGroups/MatchingToolGroupService/Matching.js @@ -4,9 +4,9 @@ import ToolGroup from '../../lib/ToolGroup'; @injectable() class Matching extends ToolGroup { tools = []; - constructor() { + constructor(@inject('MatchingQuestion') matchingQuestion) { super(); - this.tools = []; + this.tools = [matchingQuestion]; } } -- GitLab