From 2e027a77944c4e88050ec54b76fe650fe7d2964a Mon Sep 17 00:00:00 2001
From: Giannis Kopanas <jkopanas@gmail.com>
Date: Wed, 18 Dec 2019 13:13:40 +0200
Subject: [PATCH] fix(schema): problem calling schema before boot register

---
 wax-prosemirror-core/src/Application.js       |  1 +
 .../CodeService/CodeService.js                |  3 ++-
 .../src/RulesService/RulesService.js          |  7 ++++--
 .../src/SchemaService/ParseRule.js            | 22 ++++++++++++-------
 .../src/SchemaService/Schema.js               |  2 ++
 wax-prosemirror-schema/src/editoria/marks.js  | 12 +++++-----
 6 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js
index 15e88d829..cee436005 100644
--- a/wax-prosemirror-core/src/Application.js
+++ b/wax-prosemirror-core/src/Application.js
@@ -8,6 +8,7 @@ export default class Application {
   container = {};
   config = {};
   PmPlugins = {};
+
   constructor(container) {
     this.container = container;
     this.PmPlugins = container.get("PmPlugins");
diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js
index 9939652f3..2baafb752 100644
--- a/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js
+++ b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js
@@ -5,9 +5,10 @@ console.log(codeMark);
 class CodeService extends Service {
   boot() {
     const createMark = this.container.get("CreateMark");
+
     createMark({
       code: {
-        parseDOM: [{ tag: "code" }],
+        parseDOM: { tag: "code" },
         toDOM(hook, next) {
           hook.value = ["code", 0];
           next();
diff --git a/wax-prosemirror-plugins/src/RulesService/RulesService.js b/wax-prosemirror-plugins/src/RulesService/RulesService.js
index f7e5bc574..a1a578ef0 100644
--- a/wax-prosemirror-plugins/src/RulesService/RulesService.js
+++ b/wax-prosemirror-plugins/src/RulesService/RulesService.js
@@ -11,10 +11,13 @@ export default class RulesService extends Service {
   register() {
     const PmPlugins = this.app.PmPlugins;
     const configRules = this.config;
-    const { schema } = this;
+
     this.container
       .bind("Rules")
-      .toDynamicValue(() => new Rules(schema, PmPlugins))
+      .toDynamicValue(() => {
+        const { schema } = this;
+        return new Rules(schema, PmPlugins);
+      })
       .inSingletonScope();
     const rules = this.container.get("Rules");
     rules.addRule(configRules);
diff --git a/wax-prosemirror-plugins/src/SchemaService/ParseRule.js b/wax-prosemirror-plugins/src/SchemaService/ParseRule.js
index 3245551c6..5f757b0fe 100644
--- a/wax-prosemirror-plugins/src/SchemaService/ParseRule.js
+++ b/wax-prosemirror-plugins/src/SchemaService/ParseRule.js
@@ -3,30 +3,36 @@ import Middleware from "../lib/Middleware";
 
 export default class ParseRule {
   tag = "";
-  exporter = {};
+  exporter = null;
 
   constructor({ getAttrs, tag }) {
     this.tag = tag;
-    this.exporter = new Middleware();
+    if (getAttrs) {
+      this.exporter = new Middleware();
+    }
     this.addStack(getAttrs);
   }
 
   addStack(getAttrs) {
-    this.exporter.use(getAttrs);
+    if (getAttrs) {
+      this.exporter.use(getAttrs);
+    }
   }
 
   parseSchema(exporter) {
-    return {
-      tag: this.tag,
-      getAttrs(dom) {
+    const rule = { tag: this.tag };
+    if (this.exporter) {
+      rule.getAttrs = dom => {
         let hooks = {};
 
         exporter.go({ dom }, hook => {
           hooks = hook;
         });
         return omit(hooks, ["dom"]);
-      }
-    };
+      };
+    }
+    console.log(rule, "rule");
+    return rule;
   }
 
   combineRules() {
diff --git a/wax-prosemirror-plugins/src/SchemaService/Schema.js b/wax-prosemirror-plugins/src/SchemaService/Schema.js
index 197d67fb0..dfa6a68a3 100644
--- a/wax-prosemirror-plugins/src/SchemaService/Schema.js
+++ b/wax-prosemirror-plugins/src/SchemaService/Schema.js
@@ -10,6 +10,7 @@ export default class Schema {
   _nodes = {};
   _marks = {};
   schema = null;
+
   has(instance) {
     if (instance instanceof Node) {
       return this._nodes[instance.name] ? this._nodes[instance.name] : false;
@@ -50,6 +51,7 @@ export default class Schema {
     for (let index in this._marks) {
       marks[index] = this._marks[index].toJSON();
     }
+
     return new PmPschema({ nodes, marks });
   }
 }
diff --git a/wax-prosemirror-schema/src/editoria/marks.js b/wax-prosemirror-schema/src/editoria/marks.js
index d5792ded5..f4c577419 100644
--- a/wax-prosemirror-schema/src/editoria/marks.js
+++ b/wax-prosemirror-schema/src/editoria/marks.js
@@ -51,12 +51,12 @@ const marks = {
       return strongDOM;
     }
   },
-  code: {
-    parseDOM: [{ tag: "code" }],
-    toDOM() {
-      return codeDOM;
-    }
-  },
+  // code: {
+  //   parseDOM: [{ tag: "code" }],
+  //   toDOM() {
+  //     return codeDOM;
+  //   }
+  // },
   subscript: {
     excludes: "superscript",
     parseDOM: [{ tag: "sub" }, { style: "vertical-align=sub" }],
-- 
GitLab