diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js index cee436005fbc2fbdfeb7d910c41451282fd8d64b..54f0b4fb0e4f36724da11c712d2127e9beff0622 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 = {}; + schema = {}; constructor(container) { this.container = container; @@ -53,8 +54,8 @@ export default class Application { } getSchema() { - const schema = this.container.get("Schema"); - return schema.getSchema(); + this.schema = this.container.get("Schema"); + return this.schema.getSchema(); } static create(config) { @@ -70,6 +71,7 @@ export default class Application { .bind("PmPlugins") .to(PmPlugins) .inSingletonScope(); + container.bind("Wax").toFactory(() => new Application(container)); container.bind("config").toConstantValue(defaultConfig); container diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index 61aa1328df2afd0f06222d4e34a4da3e9de707fc..0ee634bb16b3a2440ce420c8aa4d011348f322a6 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -42,6 +42,7 @@ class Wax extends Component { constructor(props) { super(props); this.application = Application.create(props); + const schema = this.application.getSchema(); this.application.bootServices(); const { value, onChange } = this.props; @@ -55,8 +56,6 @@ class Wax extends Component { ...this.application.getPlugins() ]); - const schema = this.application.getSchema(); - this.WaxOptions = { schema, plugins: finalPlugins diff --git a/wax-prosemirror-core/src/config/defaultConfig.js b/wax-prosemirror-core/src/config/defaultConfig.js index ae42087113d723e29ca5edf48256e4a6f6b06270..4dd44abb170c3b18f4321bc0d026dad0041dd9f3 100644 --- a/wax-prosemirror-core/src/config/defaultConfig.js +++ b/wax-prosemirror-core/src/config/defaultConfig.js @@ -3,13 +3,14 @@ import { AnnotationService, ImageService, MenuService, + SchemaService, RedoUndoService, PlaceholderService, RulesService, - SchemaService, ShortCutsService, TextStyleService, - InlineAnnotationsService + InlineAnnotationsService, + LinkService } from "wax-prosemirror-plugins"; export default { @@ -24,6 +25,7 @@ export default { new TextStyleService(), new PlaceholderService(), new ImageService(), - new InlineAnnotationsService() + new InlineAnnotationsService(), + new LinkService() ] }; diff --git a/wax-prosemirror-plugins/src/AnnotationService/tools/Link.js b/wax-prosemirror-plugins/src/AnnotationService/tools/Link.js deleted file mode 100644 index c8cc20bb02172673aa1306cba9ce2de0b1cc19af..0000000000000000000000000000000000000000 --- a/wax-prosemirror-plugins/src/AnnotationService/tools/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/AnnotationService/tools/index.js b/wax-prosemirror-plugins/src/AnnotationService/tools/index.js index 8cfbcc999ac46aa50154ab5090ba6acff9aa8984..9d57c1c80bd447e46cd1b78928c913bd61b19b56 100644 --- a/wax-prosemirror-plugins/src/AnnotationService/tools/index.js +++ b/wax-prosemirror-plugins/src/AnnotationService/tools/index.js @@ -1,7 +1,5 @@ export { default as Blockquote } from "./Blockquote"; export { default as Em } from "./Em"; -// export { default as Code } from "./Code"; -export { default as Link } from "./Link"; export { default as SmallCaps } from "./SmallCaps"; export { default as StrikeThrough } from "./StrikeThrough"; export { default as Strong } from "./Strong"; diff --git a/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js index 2baafb75211b7f09334e5eb9b24e237bf9fd7f70..3797086fc7fcba6e1f446766cdac40c6c3ac8545 100644 --- a/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js +++ b/wax-prosemirror-plugins/src/InlineAnnotations/CodeService/CodeService.js @@ -1,24 +1,23 @@ 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(hook, next) { - hook.value = ["code", 0]; - next(); - } - } - }); + this.container.bind("Code").to(Code); } register() { - this.container.bind("Code").to(Code); + this.container + .bind("schema") + .toConstantValue({ + code: { + parseDOM: { tag: "code" }, + toDOM(hook, next) { + hook.value = ["code", 0]; + next(); + } + } + }) + .whenTargetNamed("node"); } } diff --git a/wax-prosemirror-plugins/src/LinkService/LinkService.js b/wax-prosemirror-plugins/src/LinkService/LinkService.js index dd405e79734e27f8e4ff9e8c36957abb53f17114..2746977dae7f82a409ecbcfee2cf29c25add1ad9 100644 --- a/wax-prosemirror-plugins/src/LinkService/LinkService.js +++ b/wax-prosemirror-plugins/src/LinkService/LinkService.js @@ -1,21 +1,45 @@ -import LinkPlugin from "./LinkPlugin"; import Service from "wax-prosemirror-core/src/services/Service"; -import find from "./pmPlugins/find"; -import placeholder from "./pmPlugins/placeholder"; +import LinkComponent from "./LinkComponent"; +import LinkTool from "./LinkTool"; -export default class myLinkPluginService extends Service { +export default class LinkService extends Service { name = "LinkPlugin"; boot() { - const test = this.container.get("LinkPlugin"); - console.log(test); + //Set Layout + const layout = this.container.get("Layout"); + layout.addComponent("editorOverlays", LinkComponent); } register() { - this.container.bind(this.name).to(LinkPlugin); - - this.container.bind("findPlugin").toFactory(find); - - this.container.bind("placeholderPlugin").toFactory(placeholder); + 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(); + } + } + }); + this.container.bind("Link").to(LinkTool); } } diff --git a/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js b/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js index 6c04a3625564a6869b7541b7e52e49570b819e0d..f0751e9b26846455c69d7f7a09d672fc52c99605 100644 --- a/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js +++ b/wax-prosemirror-plugins/src/PlaceholderService/PlaceholderService.js @@ -28,11 +28,12 @@ const parseTracks = str => { export default class PlaceholderService extends Service { name = "PlaceholderService"; - register() { + boot() { this.app.PmPlugins.add(PLUGIN_KEY, placeholderPlugin(PLUGIN_KEY)); + } - const createNode = this.container.get("CreateNode"); - createNode({ + register() { + this.container.bind("schema").toConstantValue({ paragraph: { group: "block", content: "inline*", @@ -57,7 +58,7 @@ export default class PlaceholderService extends Service { } }); - createNode({ + this.container.bind("schema").toConstantValue({ paragraph: { group: "block", content: "inline*", diff --git a/wax-prosemirror-plugins/src/RulesService/Rules.js b/wax-prosemirror-plugins/src/RulesService/Rules.js index 465e4fbb8390fbd23ebdb9da28e9266bac101b4c..d4e033afac476bc994983b0589fe8e42ec2c57d0 100644 --- a/wax-prosemirror-plugins/src/RulesService/Rules.js +++ b/wax-prosemirror-plugins/src/RulesService/Rules.js @@ -10,7 +10,6 @@ import { class Rules { constructor(schema, plugins) { this.PmPlugins = plugins; - this.schema = schema; this.extendedRules = this.allRules(); } @@ -19,6 +18,7 @@ class Rules { } createRules() { + debugger; const rulesCreated = inputRules({ rules: this.extendedRules }); this.PmPlugins.add("rules", rulesCreated); } @@ -27,28 +27,30 @@ class Rules { return [ ...smartQuotes, // > blockquote - wrappingInputRule(/^\s*>\s$/, this.schema.nodes.blockquote), + schema => wrappingInputRule(/^\s*>\s$/, schema.nodes.blockquote), // 1. ordered list - wrappingInputRule( - /^(\d+)\.\s$/, - this.schema.nodes.ordered_list, - match => ({ order: +match[1] }), - (match, node) => node.childCount + node.attrs.order === +match[1] - ), + schema => + wrappingInputRule( + /^(\d+)\.\s$/, + schema.nodes.ordered_list, + match => ({ order: +match[1] }), + (match, node) => node.childCount + node.attrs.order === +match[1] + ), // * bullet list - wrappingInputRule(/^\s*([-+*])\s$/, this.schema.nodes.bullet_list), + schema => wrappingInputRule(/^\s*([-+*])\s$/, schema.nodes.bullet_list), // ``` code block - textblockTypeInputRule(/^```$/, this.schema.nodes.code_block), + schema => textblockTypeInputRule(/^```$/, schema.nodes.code_block), // # heading - textblockTypeInputRule( - new RegExp("^(#{1,6})\\s$"), - this.schema.nodes.heading, - match => ({ level: match[1].length }) - ) + schema => + textblockTypeInputRule( + new RegExp("^(#{1,6})\\s$"), + schema.nodes.heading, + match => ({ level: match[1].length }) + ) ]; } } diff --git a/wax-prosemirror-plugins/src/RulesService/RulesService.js b/wax-prosemirror-plugins/src/RulesService/RulesService.js index a1a578ef0fe496fd8650a3c371ae1fd88d2a6bbf..2dc3431a65878ff3d7a52990be5b5d2a05cf65d4 100644 --- a/wax-prosemirror-plugins/src/RulesService/RulesService.js +++ b/wax-prosemirror-plugins/src/RulesService/RulesService.js @@ -5,21 +5,18 @@ export default class RulesService extends Service { name = "RulesService"; boot() { - this.container.get("Rules").createRules(); + const configRules = this.config; + const rules = this.container.get("Rules"); + rules.addRule(configRules); + rules.createRules(); } register() { const PmPlugins = this.app.PmPlugins; - const configRules = this.config; this.container .bind("Rules") - .toDynamicValue(() => { - const { schema } = this; - return new Rules(schema, PmPlugins); - }) + .toDynamicValue(() => new Rules(PmPlugins)) .inSingletonScope(); - const rules = this.container.get("Rules"); - rules.addRule(configRules); } } diff --git a/wax-prosemirror-plugins/src/SchemaService/Schema.js b/wax-prosemirror-plugins/src/SchemaService/Schema.js index dfa6a68a38211b1baf653e20b105f12d3b81a74d..5feb0700122eeb6c43db6f012524fa539910b9c9 100644 --- a/wax-prosemirror-plugins/src/SchemaService/Schema.js +++ b/wax-prosemirror-plugins/src/SchemaService/Schema.js @@ -1,5 +1,5 @@ import { Schema as PmPschema } from "prosemirror-model"; -import { injectable } from "inversify"; +import { injectable, multiInject, named, inject } from "inversify"; import Node from "./Node"; import Mark from "./Mark"; @@ -11,6 +11,20 @@ export default class Schema { _marks = {}; schema = null; + constructor( + @multiInject("schema") @named("mark") marks, + @multiInject("schema") @named("node") nodes, + @inject("CreateNode") createNode, + @inject("CreateMark") createMark + ) { + this._nodes = nodes.map(node => { + createNode(node); + }); + this._marks = marks.map(mark => { + createMark(mark); + }); + } + has(instance) { if (instance instanceof Node) { return this._nodes[instance.name] ? this._nodes[instance.name] : false; @@ -52,6 +66,7 @@ export default class Schema { marks[index] = this._marks[index].toJSON(); } - return new PmPschema({ nodes, marks }); + this.schema = new PmPschema({ nodes, marks }); + return this.schema; } } diff --git a/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js b/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js index 5424d0cd38760f07fbaffd913b39bbff0d9e6dd0..fb4dd8e7ff5cc5f12a912123661f31720eefffd8 100644 --- a/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js +++ b/wax-prosemirror-plugins/src/ShortCutsService/ShortCutsService.js @@ -5,5 +5,6 @@ export default class ShortCutsService extends Service { name = "ShortCutsService"; boot() {} + register() {} } diff --git a/wax-prosemirror-schema/src/editoria/marks.js b/wax-prosemirror-schema/src/editoria/marks.js index f4c577419bc8bae0bf1d40303e185e2095ab2206..aa3a786d6cea090c2d96ee67e3775c56aaf40f04 100644 --- a/wax-prosemirror-schema/src/editoria/marks.js +++ b/wax-prosemirror-schema/src/editoria/marks.js @@ -3,32 +3,32 @@ const emDOM = ["em", 0], codeDOM = ["code", 0]; const marks = { - link: { - attrs: { - href: { default: null }, - rel: { default: "" }, - target: { default: "blank" }, - title: { default: null } - }, - inclusive: false, - parseDOM: [ - { - tag: "a[href]", - getAttrs: dom => { - const href = dom.getAttribute("href"); - const target = href && href.indexOf("#") === 0 ? "" : "blank"; - return { - href: dom.getAttribute("href"), - title: dom.getAttribute("title"), - target - }; - } - } - ], - toDOM(node) { - return ["a", node.attrs, 0]; - } - }, + // link: { + // attrs: { + // href: { default: null }, + // rel: { default: "" }, + // target: { default: "blank" }, + // title: { default: null } + // }, + // inclusive: false, + // parseDOM: [ + // { + // tag: "a[href]", + // getAttrs: dom => { + // const href = dom.getAttribute("href"); + // const target = href && href.indexOf("#") === 0 ? "" : "blank"; + // return { + // href: dom.getAttribute("href"), + // title: dom.getAttribute("title"), + // target + // }; + // } + // } + // ], + // toDOM(node) { + // return ["a", node.attrs, 0]; + // } + // }, em: { parseDOM: [{ tag: "i" }, { tag: "em" }, { style: "font-style=italic" }], toDOM() {