From 92a2514f92f135cb905e1311202a64118cea243b Mon Sep 17 00:00:00 2001 From: Giannis Kopanas <jkopanas@gmail.com> Date: Thu, 19 Dec 2019 18:17:33 +0200 Subject: [PATCH] fix(services): add schema of inline Annotation --- .../EmphasisService/EmphasisService.js | 13 +++---- .../src/InlineAnnotations/LinkService/Link.js | 35 ------------------- .../LinkService/LinkService.js | 17 --------- .../StrongService/StrongService.js | 13 +++---- .../src/InlineAnnotations/index.js | 8 +---- .../src/LinkService/LinkService.js | 31 +++------------- .../src/RulesService/Rules.js | 4 +-- 7 files changed, 21 insertions(+), 100 deletions(-) delete mode 100644 wax-prosemirror-plugins/src/InlineAnnotations/LinkService/Link.js delete mode 100644 wax-prosemirror-plugins/src/InlineAnnotations/LinkService/LinkService.js diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/EmphasisService/EmphasisService.js b/wax-prosemirror-plugins/src/InlineAnnotations/EmphasisService/EmphasisService.js index f86f61305..190a397ab 100644 --- a/wax-prosemirror-plugins/src/InlineAnnotations/EmphasisService/EmphasisService.js +++ b/wax-prosemirror-plugins/src/InlineAnnotations/EmphasisService/EmphasisService.js @@ -3,14 +3,15 @@ import { emphasisMark } from "wax-prosemirror-schema"; import Emphasis from "./Emphasis"; class EmphasisService extends Service { - boot() { - const createMark = this.container.get("CreateMark"); - - createMark({ em: emphasisMark }); - } - register() { this.container.bind("Emphasis").to(Emphasis); + + this.container + .bind("schema") + .toConstantValue({ + em: emphasisMark + }) + .whenTargetNamed("mark"); } } diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/LinkService/Link.js b/wax-prosemirror-plugins/src/InlineAnnotations/LinkService/Link.js deleted file mode 100644 index c8cc20bb0..000000000 --- a/wax-prosemirror-plugins/src/InlineAnnotations/LinkService/Link.js +++ /dev/null @@ -1,35 +0,0 @@ -import { toggleMark } from "prosemirror-commands"; -import { markActive, promptForURL } from "../../lib/Utils"; -import Tools from "../../lib/Tools"; -import { injectable } from "inversify"; -import { icons } from "wax-prosemirror-components"; - -@injectable() -export default class Link extends Tools { - title = "Add or remove link"; - content = icons.link; - - get run() { - return (state, dispatch) => { - if (markActive(state.config.schema.marks.link)(state)) { - toggleMark(state.config.schema.marks.link)(state, dispatch); - return true; - } - - const href = promptForURL(); - if (!href) return false; - - toggleMark(state.config.schema.marks.link, { href })(state, dispatch); - }; - } - - get enable() { - return state => !state.selection.empty; - } - - get active() { - return state => { - return markActive(state.config.schema.marks.link)(state); - }; - } -} diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/LinkService/LinkService.js b/wax-prosemirror-plugins/src/InlineAnnotations/LinkService/LinkService.js deleted file mode 100644 index 10720c671..000000000 --- a/wax-prosemirror-plugins/src/InlineAnnotations/LinkService/LinkService.js +++ /dev/null @@ -1,17 +0,0 @@ -import Service from "wax-prosemirror-core/src/services/Service"; -import { linkMark } from "wax-prosemirror-schema"; -import Link from "./Link"; - -class LinkService extends Service { - boot() { - const createMark = this.container.get("CreateMark"); - - createMark({ link: linkMark }); - } - - register() { - this.container.bind("Link").to(Link); - } -} - -export default LinkService; diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/StrongService/StrongService.js b/wax-prosemirror-plugins/src/InlineAnnotations/StrongService/StrongService.js index fe29b8911..cd954b8fb 100644 --- a/wax-prosemirror-plugins/src/InlineAnnotations/StrongService/StrongService.js +++ b/wax-prosemirror-plugins/src/InlineAnnotations/StrongService/StrongService.js @@ -3,14 +3,15 @@ import { strongMark } from "wax-prosemirror-schema"; import Strong from "./Strong"; class StrongService extends Service { - boot() { - const createMark = this.container.get("CreateMark"); - - createMark({ strong: strongMark }); - } - register() { this.container.bind("Strong").to(Strong); + + this.container + .bind("schema") + .toConstantValue({ + strong: strongMark + }) + .whenTargetNamed("mark"); } } diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/index.js b/wax-prosemirror-plugins/src/InlineAnnotations/index.js index 4f9703b74..af8fbbc80 100644 --- a/wax-prosemirror-plugins/src/InlineAnnotations/index.js +++ b/wax-prosemirror-plugins/src/InlineAnnotations/index.js @@ -1,10 +1,4 @@ import CodeService from "./CodeService/CodeService"; import StrongService from "./StrongService/StrongService"; -import LinkService from "./LinkService/LinkService"; import EmphasisService from "./EmphasisService/EmphasisService"; -export default [ - new CodeService(), - new StrongService(), - new LinkService(), - new EmphasisService() -]; +export default [new CodeService(), new StrongService(), new EmphasisService()]; diff --git a/wax-prosemirror-plugins/src/LinkService/LinkService.js b/wax-prosemirror-plugins/src/LinkService/LinkService.js index 263dc15fb..695d9a7c4 100644 --- a/wax-prosemirror-plugins/src/LinkService/LinkService.js +++ b/wax-prosemirror-plugins/src/LinkService/LinkService.js @@ -1,5 +1,6 @@ import Service from "wax-prosemirror-core/src/services/Service"; import LinkComponent from "./LinkComponent"; +import { linkMark } from "wax-prosemirror-schema"; import LinkTool from "./LinkTool"; export default class LinkService extends Service { @@ -12,37 +13,13 @@ export default class LinkService extends Service { } register() { + this.container.bind("Link").to(LinkTool); + this.container .bind("schema") .toConstantValue({ - link: { - attrs: { - href: { default: null }, - rel: { default: "" }, - target: { default: "blank" }, - title: { default: null } - }, - inclusive: false, - parseDOM: { - tag: "a[href]", - getAttrs: (hook, next) => { - const href = hook.dom.getAttribute("href"); - const target = href && href.indexOf("#") === 0 ? "" : "blank"; - Object.assign(hook, { - href: hook.dom.getAttribute("href"), - title: hook.dom.getAttribute("title"), - target - }); - next(); - } - }, - toDOM(hook, next) { - hook.value = ["a", node.attrs, 0]; - next(); - } - } + link: linkMark }) .whenTargetNamed("mark"); - this.container.bind("Link").to(LinkTool); } } diff --git a/wax-prosemirror-plugins/src/RulesService/Rules.js b/wax-prosemirror-plugins/src/RulesService/Rules.js index 813f2ae34..43c7fa154 100644 --- a/wax-prosemirror-plugins/src/RulesService/Rules.js +++ b/wax-prosemirror-plugins/src/RulesService/Rules.js @@ -10,7 +10,7 @@ import { class Rules { constructor(plugins, schema) { this.PmPlugins = plugins; - debugger; + this.schema = schema; this.extendedRules = this.allRules(); } @@ -42,7 +42,7 @@ class Rules { wrappingInputRule(/^\s*([-+*])\s$/, this.schema.nodes.bullet_list), // ``` code block - schema => textblockTypeInputRule(/^```$/, schema.nodes.code_block), + textblockTypeInputRule(/^```$/, this.schema.nodes.code_block), // # heading textblockTypeInputRule( -- GitLab