From dfdde04ff7a2ac2bde788e090c08f83703c74d36 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Thu, 20 Jun 2024 23:43:17 +0300
Subject: [PATCH] new layout render

---
 editors/demo/src/Editoria/Editoria.js           |  6 +++---
 editors/demo/src/Editors.js                     |  2 +-
 .../LayoutService/components/LayoutFactory.js   |  2 +-
 wax-prosemirror-core/src/useWaxView.js          | 17 +++++++++++------
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js
index 6a3bd45c7..d78339fb3 100644
--- a/editors/demo/src/Editoria/Editoria.js
+++ b/editors/demo/src/Editoria/Editoria.js
@@ -77,9 +77,9 @@ const Editoria = () => {
         // readonly
         layout={layout}
         name={myName}
-        // onChange={debounce(source => {
-        //   console.log(JSON.stringify(source));
-        // }, 200)}
+        onChange={debounce(source => {
+          console.log(JSON.stringify(source));
+        }, 200)}
         user={user}
         scrollMargin={200}
         scrollThreshold={200}
diff --git a/editors/demo/src/Editors.js b/editors/demo/src/Editors.js
index 9227cb24d..02c1e2bd0 100644
--- a/editors/demo/src/Editors.js
+++ b/editors/demo/src/Editors.js
@@ -91,7 +91,7 @@ const Editors = () => {
       case 'oen':
         return <OEN />;
       default:
-        return <HHMI />;
+        return <Editoria />;
     }
   };
 
diff --git a/wax-prosemirror-core/src/config/defaultServices/LayoutService/components/LayoutFactory.js b/wax-prosemirror-core/src/config/defaultServices/LayoutService/components/LayoutFactory.js
index b7011ad96..9e43e79f3 100644
--- a/wax-prosemirror-core/src/config/defaultServices/LayoutService/components/LayoutFactory.js
+++ b/wax-prosemirror-core/src/config/defaultServices/LayoutService/components/LayoutFactory.js
@@ -1,4 +1,4 @@
 /* eslint-disable react/jsx-props-no-spreading */
 import React from 'react';
 
-export default Component => props => <Component {...props} />;
+export default Component => props => Component;
diff --git a/wax-prosemirror-core/src/useWaxView.js b/wax-prosemirror-core/src/useWaxView.js
index 42f187b37..d3ee0c30e 100644
--- a/wax-prosemirror-core/src/useWaxView.js
+++ b/wax-prosemirror-core/src/useWaxView.js
@@ -1,6 +1,6 @@
 /* eslint-disable consistent-return */
 /* eslint-disable react/prop-types */
-import { useContext, useEffect, useImperativeHandle } from 'react';
+import { useContext, useEffect, useImperativeHandle, useState } from 'react';
 import { EditorState } from 'prosemirror-state';
 import { EditorView } from 'prosemirror-view';
 import trackedTransaction from './utilities/track-changes/trackedTransaction';
@@ -11,7 +11,7 @@ import helpers from './helpers/helpers';
 import './styles/styles.css';
 
 let previousDoc;
-let view;
+
 const useWaxView = props => {
   const {
     browserSpellCheck,
@@ -24,19 +24,21 @@ const useWaxView = props => {
     serializer,
     scrollMargin,
     scrollThreshold,
+    onChange,
   } = props;
-
   const context = useContext(WaxContext);
+  const [WaxView, setWaxView] = useState(null);
   const { createPortal } = useContext(PortalContext);
 
   context.app.setContext({ ...context, createPortal });
   const schema = context.app.getSchema();
-
+  let view;
   useEffect(() => {
     context.app.bootServices();
     context.app.getShortCuts();
     context.app.getRules();
 
+    console.log('all props', props);
     const options = WaxOptions({
       ...props,
       schema,
@@ -57,12 +59,15 @@ const useWaxView = props => {
       },
     });
 
+    setWaxView(view);
+
     context.updateView(
       {
         main: view,
       },
       'main',
     );
+
     setTimeout(() => {
       if (autoFocus && view) {
         view.focus();
@@ -96,7 +101,7 @@ const useWaxView = props => {
     const docContent =
       targetFormat === 'JSON' ? state.doc.toJSON() : state.doc.content;
     if (!previousDoc.eq(view.state.doc) || tr.getMeta('forceUpdate'))
-      props.onChange(docContent);
+      if (onChange) onChange(docContent);
 
     /* when a transaction comes from a view other than
       main don't keep updating the view ,as this is
@@ -114,7 +119,7 @@ const useWaxView = props => {
     }
   };
 
-  return view;
+  return WaxView;
 };
 
 export default useWaxView;
-- 
GitLab