From 107c3478fa421fb9eace3ea6e82c24d7b199a414 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 29 Mar 2022 18:29:44 +0300 Subject: [PATCH] new command --- .../src/components/Button.js | 8 +++---- wax-prosemirror-core/src/WaxView.js | 4 +++- .../src/MatchingService/MatchingQuestion.js | 24 +++++++++++++++---- .../components/EditorComponent.js | 5 ++-- .../schema/matchingContainerNode.js | 4 +++- .../schema/matchingOptionNode.js | 8 +++---- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/wax-prosemirror-components/src/components/Button.js b/wax-prosemirror-components/src/components/Button.js index 911932b5d..464a0ae13 100644 --- a/wax-prosemirror-components/src/components/Button.js +++ b/wax-prosemirror-components/src/components/Button.js @@ -18,9 +18,9 @@ const Button = ({ view = {}, item }) => { const { state } = view; - const handleMouseDown = (e, editorState, editorDispatch) => { + const handleMouseDown = e => { e.preventDefault(); - run(editorState, editorDispatch); + run(activeView.state, activeView.dispatch, activeView); }; const isActive = !!( @@ -38,9 +38,7 @@ const Button = ({ view = {}, item }) => { disabled={isDisabled} iconName={icon} label={label} - onMouseDown={e => - handleMouseDown(e, activeView.state, activeView.dispatch) - } + onMouseDown={e => handleMouseDown(e)} title={title} /> ), diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index f636490b3..45382705d 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -105,7 +105,9 @@ const WaxView = forwardRef((props, ref) => { if (autoFocus && view) setTimeout(() => { view.focus(); - }, 1000); + view.state.tr.insertText('', 0); + view.dispatch(view.state.tr); + }, 500); return () => view.destroy(); } diff --git a/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js b/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js index 2b3c198ca..03cdfece5 100644 --- a/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js +++ b/wax-prosemirror-services/src/MatchingService/MatchingQuestion.js @@ -1,11 +1,26 @@ import { injectable } from 'inversify'; -import { wrapIn } from 'prosemirror-commands'; import { Fragment } from 'prosemirror-model'; import { findWrapping } from 'prosemirror-transform'; import { TextSelection } from 'prosemirror-state'; +import { Commands } from 'wax-prosemirror-utilities'; + import { v4 as uuidv4 } from 'uuid'; import Tools from '../lib/Tools'; +const checkifEmpty = view => { + const { state } = view; + const { from, to } = state.selection; + state.doc.nodesBetween(from, to, (node, pos) => { + if (node.textContent !== ' ') Commands.simulateKey(view, 13, 'Enter'); + }); + if (state.selection.constructor.name === 'GapCursor') { + Commands.simulateKey(view, 13, 'Enter'); + setTimeout(() => { + view.focus(); + }); + } +}; + @injectable() class MatchingQuestion extends Tools { title = 'Add Matching'; @@ -13,11 +28,12 @@ class MatchingQuestion extends Tools { name = 'Matching'; get run() { - return (state, dispatch) => { + return (state, dispatch, view) => { + checkifEmpty(view); /* Create Wrapping */ - const { $from, $to } = state.selection; + const { $from, $to } = view.state.selection; const range = $from.blockRange($to); - const { tr } = state; + const { tr } = view.state; const wrapping = range && diff --git a/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js b/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js index 9f4cc72aa..adbcff64e 100644 --- a/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js +++ b/wax-prosemirror-services/src/MatchingService/components/EditorComponent.js @@ -17,17 +17,18 @@ const EditorWrapper = styled.div` flex: 2 1 auto; justify-content: left; - .ProseMirror { + > .ProseMirror { white-space: break-spaces; width: 100%; word-wrap: break-word; + padding: 0 !important; &:focus { outline: none; } :empty::before { - content: 'Type your answer'; + content: 'Type your text'; color: #aaa; float: left; font-style: italic; diff --git a/wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js b/wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js index 887d518de..bc0ba1c2b 100644 --- a/wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js +++ b/wax-prosemirror-services/src/MatchingService/schema/matchingContainerNode.js @@ -2,7 +2,8 @@ const matchingContainerNode = { attrs: { id: { default: '' }, class: { default: 'matching-container' }, - questions: { default: { question: [], answer: '' } }, + answers: { default: [] }, + feedback: { default: '' }, }, group: 'block questions', atom: true, @@ -14,6 +15,7 @@ const matchingContainerNode = { return { id: dom.getAttribute('id'), class: dom.getAttribute('class'), + feedback: dom.getAttribute('feedback'), }; }, }, diff --git a/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js b/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js index e07647b7c..0e70af423 100644 --- a/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js +++ b/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js @@ -4,10 +4,11 @@ const matchingOptionNode = { id: { default: '' }, correct: { default: false }, answer: { default: false }, - feedback: { default: '' }, }, - group: 'block questions', - content: 'block*', + group: 'inline questions', + content: 'text*', + inline: true, + atom: true, defining: true, parseDOM: [ { @@ -18,7 +19,6 @@ const matchingOptionNode = { class: dom.getAttribute('class'), correct: JSON.parse(dom.getAttribute('correct').toLowerCase()), answer: JSON.parse(dom.getAttribute('answer').toLowerCase()), - feedback: dom.getAttribute('feedback'), }; }, }, -- GitLab