From 34cd9c6e667e68a2b48d7fb0c848dac88527f803 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Tue, 18 May 2021 11:15:26 +0300
Subject: [PATCH] use note groups for save

---
 editors/demo/src/Editoria/Editoria.js         |  2 +-
 wax-prosemirror-core/src/Wax.js               | 41 ++++++++++++-------
 .../src/nodes/footNoteNode.js                 |  2 +-
 3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js
index 42a690860..98a5f9cb5 100644
--- a/editors/demo/src/Editoria/Editoria.js
+++ b/editors/demo/src/Editoria/Editoria.js
@@ -50,7 +50,7 @@ const Editoria = () => {
           value={demo}
           // readonly
           layout={layout}
-          // onChange={source => console.log(source)}
+          onChange={source => console.log(source)}
           user={user}
         />
       </>
diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js
index fb4449b8c..09f5faf63 100644
--- a/wax-prosemirror-core/src/Wax.js
+++ b/wax-prosemirror-core/src/Wax.js
@@ -1,7 +1,7 @@
 /* eslint react/prop-types: 0 */
 import React, { useEffect, useState } from 'react';
 import debounce from 'lodash/debounce';
-
+import { each } from 'lodash';
 import { DOMSerializer } from 'prosemirror-model';
 
 import WaxProvider from './WaxContext';
@@ -56,13 +56,21 @@ const Wax = props => {
       content => {
         /* HACK  alter toDOM of footnote, because of how PM treats inline nodes
       with content */
-        if (schema.nodes.footnote) {
-          const old = schema.nodes.footnote.spec.toDOM;
-          schema.nodes.footnote.spec.toDOM = node => {
-            // eslint-disable-next-line prefer-rest-params
-            old.apply(this);
-            if (node) return ['footnote', node.attrs, 0];
-          };
+
+        const notes = [];
+        each(schema.nodes, node => {
+          if (node.groups.includes('notes')) notes.push(node);
+        });
+
+        if (notes.length > 0) {
+          notes.forEach(note => {
+            const old = schema.nodes[note.name].spec.toDOM;
+            schema.nodes[note.name].spec.toDOM = node => {
+              // eslint-disable-next-line prefer-rest-params
+              old.apply(this);
+              if (node) return [note.name, node.attrs, 0];
+            };
+          });
         }
 
         if (targetFormat === 'JSON') {
@@ -71,13 +79,16 @@ const Wax = props => {
           const serialize = serializer(schema);
           WaxOnchange(serialize(content));
         }
-        if (schema.nodes.footnote) {
-          const old = schema.nodes.footnote.spec.toDOM;
-          schema.nodes.footnote.spec.toDOM = node => {
-            // eslint-disable-next-line prefer-rest-params
-            old.apply(this);
-            if (node) return ['footnote', node.attrs];
-          };
+
+        if (notes.length > 0) {
+          notes.forEach(note => {
+            const old = schema.nodes[note.name].spec.toDOM;
+            schema.nodes[note.name].spec.toDOM = node => {
+              // eslint-disable-next-line prefer-rest-params
+              old.apply(this);
+              if (node) return [note.name, node.attrs];
+            };
+          });
         }
       },
       1000,
diff --git a/wax-prosemirror-schema/src/nodes/footNoteNode.js b/wax-prosemirror-schema/src/nodes/footNoteNode.js
index 38b81a211..ab89aa79a 100644
--- a/wax-prosemirror-schema/src/nodes/footNoteNode.js
+++ b/wax-prosemirror-schema/src/nodes/footNoteNode.js
@@ -1,5 +1,5 @@
 const footnote = {
-  group: 'notes, inline',
+  group: 'notes inline',
   content: 'inline*',
   inline: true,
   atom: true,
-- 
GitLab