From 1a23fb4fb0078ce944ee7ae637655558bd43cbc1 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Sun, 20 Nov 2022 12:13:03 +0200
Subject: [PATCH] saveContent

---
 wax-prosemirror-core/src/Wax.js             |  9 +----
 wax-prosemirror-core/src/helpers/helpers.js | 44 ++++++++++++++++++++-
 2 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js
index 5f955b453..a4cc8235e 100644
--- a/wax-prosemirror-core/src/Wax.js
+++ b/wax-prosemirror-core/src/Wax.js
@@ -52,14 +52,7 @@ const Wax = forwardRef((props, ref) => {
   const finalOnChange = content => {
     if (!onChange) return;
     const { schema } = application.schema;
-    helpers.alterNotesSchema(schema);
-    if (targetFormat === 'JSON') {
-      onChange(content);
-    } else {
-      const serialize = serializer(schema);
-      onChange(serialize(content));
-    }
-    helpers.revertNotesSchema(schema);
+    helpers.saveContent(content, onChange, schema, serializer, targetFormat);
   };
 
   const Layout = application.container.get('Layout');
diff --git a/wax-prosemirror-core/src/helpers/helpers.js b/wax-prosemirror-core/src/helpers/helpers.js
index 0041106f9..ab26271ef 100644
--- a/wax-prosemirror-core/src/helpers/helpers.js
+++ b/wax-prosemirror-core/src/helpers/helpers.js
@@ -1,6 +1,36 @@
 /* eslint-disable no-param-reassign */
 import { each } from 'lodash';
 
+// const alterNotesSchema = schema => {
+//   const notes = [];
+//   each(schema.nodes, node => {
+//     if (node.groups.includes('notes')) notes.push(node);
+//   });
+//   if (notes.length > 0) {
+//     notes.forEach(note => {
+//       schema.nodes[note.name].spec.toDOM = node => {
+//         if (node) return [note.name, node.attrs, 0];
+//         return true;
+//       };
+//     });
+//   }
+// };
+
+// const revertNotesSchema = schema => {
+//   const notes = [];
+//   each(schema.nodes, node => {
+//     if (node.groups.includes('notes')) notes.push(node);
+//   });
+//   if (notes.length > 0) {
+//     notes.forEach(note => {
+//       schema.nodes[note.name].spec.toDOM = node => {
+//         if (node) return [note.name, node.attrs];
+//         return true;
+//       };
+//     });
+//   }
+// };
+
 const alterNotesSchema = schema => {
   const notes = [];
   each(schema.nodes, node => {
@@ -45,8 +75,18 @@ const getDocContent = (schema, serializer, targetFormat, context) => {
   return content;
 };
 
+const saveContent = (content, onChange, schema, serializer, targetFormat) => {
+  alterNotesSchema(schema);
+  if (targetFormat === 'JSON') {
+    onChange(content);
+  } else {
+    const serialize = serializer(schema);
+    onChange(serialize(content));
+  }
+  revertNotesSchema(schema);
+};
+
 export default {
-  alterNotesSchema,
   getDocContent,
-  revertNotesSchema,
+  saveContent,
 };
-- 
GitLab