Skip to content
Snippets Groups Projects
Commit 2e027a77 authored by Giannis Kopanas's avatar Giannis Kopanas
Browse files

fix(schema): problem calling schema before boot register

parent b1c2a8fe
No related branches found
No related tags found
1 merge request!45Develop
...@@ -8,6 +8,7 @@ export default class Application { ...@@ -8,6 +8,7 @@ export default class Application {
container = {}; container = {};
config = {}; config = {};
PmPlugins = {}; PmPlugins = {};
constructor(container) { constructor(container) {
this.container = container; this.container = container;
this.PmPlugins = container.get("PmPlugins"); this.PmPlugins = container.get("PmPlugins");
......
...@@ -5,9 +5,10 @@ console.log(codeMark); ...@@ -5,9 +5,10 @@ console.log(codeMark);
class CodeService extends Service { class CodeService extends Service {
boot() { boot() {
const createMark = this.container.get("CreateMark"); const createMark = this.container.get("CreateMark");
createMark({ createMark({
code: { code: {
parseDOM: [{ tag: "code" }], parseDOM: { tag: "code" },
toDOM(hook, next) { toDOM(hook, next) {
hook.value = ["code", 0]; hook.value = ["code", 0];
next(); next();
......
...@@ -11,10 +11,13 @@ export default class RulesService extends Service { ...@@ -11,10 +11,13 @@ export default class RulesService extends Service {
register() { register() {
const PmPlugins = this.app.PmPlugins; const PmPlugins = this.app.PmPlugins;
const configRules = this.config; const configRules = this.config;
const { schema } = this;
this.container this.container
.bind("Rules") .bind("Rules")
.toDynamicValue(() => new Rules(schema, PmPlugins)) .toDynamicValue(() => {
const { schema } = this;
return new Rules(schema, PmPlugins);
})
.inSingletonScope(); .inSingletonScope();
const rules = this.container.get("Rules"); const rules = this.container.get("Rules");
rules.addRule(configRules); rules.addRule(configRules);
......
...@@ -3,30 +3,36 @@ import Middleware from "../lib/Middleware"; ...@@ -3,30 +3,36 @@ import Middleware from "../lib/Middleware";
export default class ParseRule { export default class ParseRule {
tag = ""; tag = "";
exporter = {}; exporter = null;
constructor({ getAttrs, tag }) { constructor({ getAttrs, tag }) {
this.tag = tag; this.tag = tag;
this.exporter = new Middleware(); if (getAttrs) {
this.exporter = new Middleware();
}
this.addStack(getAttrs); this.addStack(getAttrs);
} }
addStack(getAttrs) { addStack(getAttrs) {
this.exporter.use(getAttrs); if (getAttrs) {
this.exporter.use(getAttrs);
}
} }
parseSchema(exporter) { parseSchema(exporter) {
return { const rule = { tag: this.tag };
tag: this.tag, if (this.exporter) {
getAttrs(dom) { rule.getAttrs = dom => {
let hooks = {}; let hooks = {};
exporter.go({ dom }, hook => { exporter.go({ dom }, hook => {
hooks = hook; hooks = hook;
}); });
return omit(hooks, ["dom"]); return omit(hooks, ["dom"]);
} };
}; }
console.log(rule, "rule");
return rule;
} }
combineRules() { combineRules() {
......
...@@ -10,6 +10,7 @@ export default class Schema { ...@@ -10,6 +10,7 @@ export default class Schema {
_nodes = {}; _nodes = {};
_marks = {}; _marks = {};
schema = null; schema = null;
has(instance) { has(instance) {
if (instance instanceof Node) { if (instance instanceof Node) {
return this._nodes[instance.name] ? this._nodes[instance.name] : false; return this._nodes[instance.name] ? this._nodes[instance.name] : false;
...@@ -50,6 +51,7 @@ export default class Schema { ...@@ -50,6 +51,7 @@ export default class Schema {
for (let index in this._marks) { for (let index in this._marks) {
marks[index] = this._marks[index].toJSON(); marks[index] = this._marks[index].toJSON();
} }
return new PmPschema({ nodes, marks }); return new PmPschema({ nodes, marks });
} }
} }
...@@ -51,12 +51,12 @@ const marks = { ...@@ -51,12 +51,12 @@ const marks = {
return strongDOM; return strongDOM;
} }
}, },
code: { // code: {
parseDOM: [{ tag: "code" }], // parseDOM: [{ tag: "code" }],
toDOM() { // toDOM() {
return codeDOM; // return codeDOM;
} // }
}, // },
subscript: { subscript: {
excludes: "superscript", excludes: "superscript",
parseDOM: [{ tag: "sub" }, { style: "vertical-align=sub" }], parseDOM: [{ tag: "sub" }, { style: "vertical-align=sub" }],
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment