From 3793e62f27e931113e239b5013109004559e6e4b Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Mon, 17 May 2021 18:26:53 +0300
Subject: [PATCH] temp

---
 .../MultipleChoiceQuestion.js                 | 81 ++++++++++---------
 .../MultipleChoiceQuestionService.js          |  1 +
 .../schema/multipleChoiceNode.js              |  4 +-
 .../src/SchemaService/Node.js                 | 14 ++--
 4 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js
index 4636898ea..8f34f7f0b 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestion.js
@@ -12,50 +12,55 @@ class MultipleChoiceQuestion extends Tools {
 
   get run() {
     return (state, dispatch) => {
-      console.log(state.selection);
+      console.log(state);
       const { from, to } = state.selection;
       const { tr } = state;
 
-      state.doc.nodesBetween(from, to, (node, pos) => {
-        if (node.type.name === 'question_wrapper') {
-          const { empty, $from, $to } = state.selection;
-          let content = Fragment.empty;
-          if (!empty && $from.sameParent($to) && $from.parent.inlineContent)
-            content = $from.parent.content.cut(
-              $from.parentOffset,
-              $to.parentOffset,
-            );
+      state.schema.nodes.question_wrapper.spec.atom = false;
+
+      setTimeout(() => {
+        state.doc.nodesBetween(from, to, (node, pos) => {
+          if (node.type.name === 'question_wrapper') {
+            const { empty, $from, $to } = state.selection;
+            let content = Fragment.empty;
+            if (!empty && $from.sameParent($to) && $from.parent.inlineContent)
+              content = $from.parent.content.cut(
+                $from.parentOffset,
+                $to.parentOffset,
+              );
 
-          const footnote = state.config.schema.nodes.multiple_choice.create(
-            { id: uuidv4() },
-            content,
-          );
-          dispatch(tr.replaceSelectionWith(footnote));
-        } else {
-          tr.setBlockType(
-            from,
-            to,
-            state.config.schema.nodes.question_wrapper,
-            {
-              class: 'question',
-            },
-          );
-          if (!tr.steps.length) return false;
-          const { empty, $from, $to } = state.selection;
-          let content = Fragment.empty;
-          if (!empty && $from.sameParent($to) && $from.parent.inlineContent)
-            content = $from.parent.content.cut(
-              $from.parentOffset,
-              $to.parentOffset,
+            const footnote = state.config.schema.nodes.multiple_choice.create(
+              { id: uuidv4() },
+              content,
             );
+            dispatch(tr.replaceSelectionWith(footnote));
+          } else {
+            tr.setBlockType(
+              from,
+              to,
+              state.config.schema.nodes.question_wrapper,
+              {
+                class: 'question',
+              },
+            );
+            if (!tr.steps.length) return false;
+            const { empty, $from, $to } = state.selection;
+            let content = Fragment.empty;
+            if (!empty && $from.sameParent($to) && $from.parent.inlineContent)
+              content = $from.parent.content.cut(
+                $from.parentOffset,
+                $to.parentOffset,
+              );
 
-          const footnote = state.config.schema.nodes.multiple_choice.create(
-            { id: uuidv4() },
-            content,
-          );
-          dispatch(tr.replaceSelectionWith(footnote));
-          // dispatch(state.tr.replaceSelectionWith(footnote));
-        }
+            const footnote = state.config.schema.nodes.multiple_choice.create(
+              { id: uuidv4() },
+              content,
+            );
+            dispatch(tr.replaceSelectionWith(footnote));
+            // dispatch(state.tr.replaceSelectionWith(footnote));
+          }
+        });
+        state.schema.nodes.question_wrapper.spec.atom = true;
       });
     };
   }
diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestionService.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestionService.js
index 0ae7c5fe4..af9f3bff6 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestionService.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/MultipleChoiceQuestionService.js
@@ -18,6 +18,7 @@ class MultipleChoiceQuestionService extends Service {
     createNode({
       question_wrapper: {
         group: 'block',
+        atom: true,
         content: 'inline*',
         attrs: {
           class: { default: 'paragraph' },
diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js
index ad3a371eb..b6d4b6424 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/schema/multipleChoiceNode.js
@@ -1,8 +1,8 @@
 const multipleChoiceNode = {
   group: 'inline',
   content: 'inline*',
-  inline: true,
-  // atom: true,
+  // inline: true,
+  atom: true,
   attrs: {
     id: { default: '' },
   },
diff --git a/wax-prosemirror-services/src/SchemaService/Node.js b/wax-prosemirror-services/src/SchemaService/Node.js
index ae38bf3db..b9d9e6e31 100644
--- a/wax-prosemirror-services/src/SchemaService/Node.js
+++ b/wax-prosemirror-services/src/SchemaService/Node.js
@@ -1,17 +1,17 @@
-import { isPlainObject } from "lodash";
-import ParseRule from "./ParseRule";
-import Middleware from "../lib/Middleware";
+import { isPlainObject } from 'lodash';
+import ParseRule from './ParseRule';
+import Middleware from '../lib/Middleware';
 
 export default class Node {
-  name = "";
+  name = '';
   importer = {};
 
   atom = false;
   inline = false;
   isolating = false;
   draggable = false;
-  group = "";
-  content = "";
+  group = '';
+  content = '';
   _attrs = {};
   _parseRules = [];
 
@@ -73,7 +73,7 @@ export default class Node {
           hooks = hook;
         });
         return hooks.value;
-      }
+      },
     };
   }
 }
-- 
GitLab