From d8960a9352a4567e89cc8aed8cc6592bd649892d Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 29 Mar 2022 20:28:28 +0300 Subject: [PATCH] fix command --- .../FillTheGapQuestion.js | 21 ++++++++++++++----- .../components/ContainerEditor.js | 19 ++--------------- .../components/EditorComponent.js | 8 ++++++- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestion.js b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestion.js index 1f73b94be..920ecd224 100644 --- a/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestion.js +++ b/wax-prosemirror-services/src/FillTheGapQuestionService/FillTheGapQuestion.js @@ -1,7 +1,8 @@ import { injectable } from 'inversify'; -import { wrapIn } from 'prosemirror-commands'; +import { findWrapping } from 'prosemirror-transform'; import { v4 as uuidv4 } from 'uuid'; import Tools from '../lib/Tools'; +import helpers from '../MultipleChoiceQuestionService/helpers/helpers'; @injectable() class FillTheGapQuestion extends Tools { @@ -10,10 +11,20 @@ class FillTheGapQuestion extends Tools { name = 'Fill The Gap'; get run() { - return (state, dispatch) => { - wrapIn(state.config.schema.nodes.fill_the_gap_container, { - id: uuidv4(), - })(state, dispatch); + return (state, dispatch, view) => { + helpers.checkifEmpty(view); + const { $from, $to } = view.state.selection; + const range = $from.blockRange($to); + const { tr } = view.state; + + const wrapping = + range && + findWrapping(range, state.config.schema.nodes.fill_the_gap_container, { + id: uuidv4(), + }); + if (!wrapping) return false; + tr.wrap(range, wrapping); + dispatch(tr); }; } diff --git a/wax-prosemirror-services/src/MatchingService/components/ContainerEditor.js b/wax-prosemirror-services/src/MatchingService/components/ContainerEditor.js index dbdd0de8e..273c90844 100644 --- a/wax-prosemirror-services/src/MatchingService/components/ContainerEditor.js +++ b/wax-prosemirror-services/src/MatchingService/components/ContainerEditor.js @@ -3,31 +3,16 @@ import React, { useContext, useRef, useEffect } from 'react'; import styled from 'styled-components'; import { EditorView } from 'prosemirror-view'; -import { EditorState, TextSelection } from 'prosemirror-state'; +import { EditorState } from 'prosemirror-state'; import { StepMap } from 'prosemirror-transform'; -import { keymap } from 'prosemirror-keymap'; -import { baseKeymap } from 'prosemirror-commands'; -import { undo, redo } from 'prosemirror-history'; import { WaxContext } from 'wax-prosemirror-core'; const EditorWrapper = styled.div` > .ProseMirror { - padding: 5px; + padding: 0px; &:focus { outline: none; } - - 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; - } } `; diff --git a/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js b/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js index adbcff64e..c1f858b5e 100644 --- a/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js +++ b/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js @@ -110,7 +110,13 @@ const EditorComponent = ({ node, view, getPos }) => { plugins: finalPlugins, }), dispatchTransaction, - disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'], + disallowedTools: [ + 'Images', + 'Lists', + 'lift', + 'MultipleChoice', + 'Tables', + ], handleDOMEvents: { mousedown: () => { main.dispatch( -- GitLab