From a6ca34fd83a65b5d679d200d1f769d3481ce70b6 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Tue, 17 Dec 2019 16:28:38 +0200
Subject: [PATCH] code in progress

---
 editors/editoria/src/Editoria.js              |  2 +-
 .../src/AnnotationService/tools/index.js      |  2 +-
 .../src/InlineAnnotations/CodeService/Code.js | 23 +++++++++++++++++++
 .../CodeService/CodeService.js                | 13 +++++++----
 wax-prosemirror-schema/index.js               |  1 +
 wax-prosemirror-schema/src/editoria/marks.js  | 12 +++++-----
 6 files changed, 41 insertions(+), 12 deletions(-)
 create mode 100644 wax-prosemirror-plugins/src/InlineAnnotations/CodeService/Code.js

diff --git a/editors/editoria/src/Editoria.js b/editors/editoria/src/Editoria.js
index 96aac71ec..2341165a6 100644
--- a/editors/editoria/src/Editoria.js
+++ b/editors/editoria/src/Editoria.js
@@ -48,7 +48,7 @@ const Editoria = () => (
       autoFocus
       placeholder="Type Something..."
       fileUpload={file => renderImage(file)}
-      value={text}
+      value="<p> hello <code> this is the code</code></p>"
       layout={EditoriaLayout}
       user={user}
     />
diff --git a/wax-prosemirror-plugins/src/AnnotationService/tools/index.js b/wax-prosemirror-plugins/src/AnnotationService/tools/index.js
index 30b7c19b8..8cfbcc999 100644
--- a/wax-prosemirror-plugins/src/AnnotationService/tools/index.js
+++ b/wax-prosemirror-plugins/src/AnnotationService/tools/index.js
@@ -1,6 +1,6 @@
 export { default as Blockquote } from "./Blockquote";
 export { default as Em } from "./Em";
-export { default as Code } from "./Code";
+// export { default as Code } from "./Code";
 export { default as Link } from "./Link";
 export { default as SmallCaps } from "./SmallCaps";
 export { default as StrikeThrough } from "./StrikeThrough";
diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/Code.js b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/Code.js
new file mode 100644
index 000000000..61887249a
--- /dev/null
+++ b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/Code.js
@@ -0,0 +1,23 @@
+import { toggleMark } from "prosemirror-commands";
+import { markActive } from "../../lib/Utils";
+import Tools from "../../lib/Tools";
+import { injectable } from "inversify";
+import { icons } from "wax-prosemirror-components";
+
+@injectable()
+export default class Code extends Tools {
+  title = "Toggle code";
+  content = icons.code;
+
+  get run() {
+    return (state, dispatch) => {
+      toggleMark(state.config.schema.marks.code)(state, dispatch);
+    };
+  }
+
+  get active() {
+    return state => {
+      return markActive(state.config.schema.marks.code)(state);
+    };
+  }
+}
diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js
index 2f9cad0e5..9939652f3 100644
--- a/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js
+++ b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js
@@ -1,19 +1,24 @@
 import Service from "wax-prosemirror-core/src/services/Service";
-
+import { codeMark } from "wax-prosemirror-schema";
+import Code from "./Code";
+console.log(codeMark);
 class CodeService extends Service {
   boot() {
     const createMark = this.container.get("CreateMark");
     createMark({
       code: {
         parseDOM: [{ tag: "code" }],
-        toDOM() {
-          return codeDOM;
+        toDOM(hook, next) {
+          hook.value = ["code", 0];
+          next();
         }
       }
     });
   }
 
-  register() {}
+  register() {
+    this.container.bind("Code").to(Code);
+  }
 }
 
 export default CodeService;
diff --git a/wax-prosemirror-schema/index.js b/wax-prosemirror-schema/index.js
index b89875b9b..20910b034 100644
--- a/wax-prosemirror-schema/index.js
+++ b/wax-prosemirror-schema/index.js
@@ -1,3 +1,4 @@
 export { default as DefaultSchema } from "./src/DefaultSchema";
 export { default as EditoriaSchema } from "./src/editoria/EditoriaSchema";
 export { default as XpubSchema } from "./src/XpubSchema";
+export { default as codeMark } from "./src/marks/codeMark";
diff --git a/wax-prosemirror-schema/src/editoria/marks.js b/wax-prosemirror-schema/src/editoria/marks.js
index f4c577419..d5792ded5 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